I posted this on discord and got some ideas, but still haven't quite cracked it. This is the basic idea:
1. Read a help index file - this is a list of all help topics available.
2. Loop over the items
3. For each one send("help " .. item)
4. Capture contents
5. When the prompt arrives stop capturing.
6. Resume loop.
The problem is between 5 and 6. The following is the best experiment that I've made so far which ALMOST works. It works perfectly for the first couple of hundred items, but then the global name helpitemname gets out of sync with the one which is actually sent using the send("help" .. helpitem) command. I think this is because the accumulated lag on the server over several hundred commands exceeds the 5 second slot allotted to one help/capture cycle. What I really need to do is for the capture trigger to signal back to the loop that it has finished so the next help/capture cycle can start. I tried that by means of setting a global variable to control a queue, but the main loop checking the queue locked the GUI. Not quite experienced enough with lua/mudlet to work out what to do here. Ideas welcome!
Alias: buildhelpdb:
Code: Select all
_base = getMudletHomeDir() .. "/help"
_indexfile = _base .. "/aproposdb"
items = {}
for line in io.lines(_indexfile) do
items[#items + 1] = line
end
-- test array
items = {}
items[1] = 'LOOK'
items[2] = 'GATE'
helpitemname = ''
helpitemtext = {}
delay = 5.0
for i, helpitem in ipairs(items) do
tempTimer(delay, function()
helpitemname = helpitem
helpitemtext = {}
send("help " .. helpitem)
enableTrigger("CaptureHelpText")
end)
delay = delay + 5.0
end
Code: Select all
function isMyPrompt(line)
return string.match(line, "^%(%d%d:%d%d%)")
end
local myline = line
if not isMyPrompt(myline) then
--echo("Adding line to helptext")
table.insert(helpitemtext, myline)
else
_base = getMudletHomeDir() .. "/help"
_file = _base .. "/" .. helpitemname
echo("saving helpfile to " .. _file)
recordFile = io.open( _file, "w" )
io.output( recordFile )
for _,v in ipairs(helpitemtext) do
io.write(v .. '\n')
end
io.flush()
io.close()
disableTrigger("CaptureHelpText")
end
Wod