Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Message
| I'm not sure which version of the plugin (exactly) you are using as there have been a few. However this amendment should do what you want. If you pause or abort the speedwalk it shows the rest of it as a "command stack" string.
New/changed code in bold.
function show_remainder (line)
local remainder = { }
for rem_line = line + 1, #lines do
table.insert (remainder, lines [rem_line])
end -- for remaining lines
ColourNote ("white", "green", "Remaining: " .. table.concat (remainder, ';'))
end -- show_remainder
-- main function called when you type a speedwalk
function func_handle_speedwalk (name, line, wildcards)
wait.make (function () --- coroutine below here
sw = EvaluateSpeedwalk (wildcards [1])
if string.sub (sw, 1, 1) == "*" then
ColourNote ("white", "red", string.sub (sw, 2))
return
end -- if
pause_speedwalk = false -- no pause yet
abort_speedwalk = false -- no abort yet
speedwalk_thread = coroutine.running () -- remember this thread
-- build table of speedwalk lines
lines = { } -- table of lines
for walk_line in getlines (sw) do
if string.match (walk_line, "^%s*$") then
break
end -- empty line - probably end of speedwalk
table.insert (lines, walk_line)
end -- for
-- iterate the speedwalk string, line by line, sending each line to the MUD
for line, walk_line in ipairs (lines) do
-- see if pausing wanted (global variable set)
if pause_speedwalk then
ColourNote ("white", "green", "Speedwalk paused.")
show_remainder (line)
ret = coroutine.yield ()
if ret == "abort" then
ColourNote ("black", "yellow", "Speedwalk abandoned.")
speedwalk_thread = nil
return
end -- abort speedwalk wanted
ColourNote ("white", "green", "Speedwalk resumed.")
pause_speedwalk = false
end -- if
-- see if aborting wanted
if abort_speedwalk then
ColourNote ("black", "yellow", "Speedwalk abandoned.")
show_remainder (line)
speedwalk_thread = nil
return
end -- if
-- send the speedwalk
Send (walk_line)
-- now wait for an appropriate response
line, wildcards = wait.regexp ("&exits_trigger;", &timeout_secs;)
-- check for timeout
if not line then
ColourNote ("white", "red", "Speedwalk timed-out")
speedwalk_thread = nil
return -- give up
end -- if
-- check we didn't get told it was impossible
if wildcards.exits == "" then
ColourNote ("white", "red", "Speedwalk cancelled")
speedwalk_thread = nil
return -- give up
end -- if
-- pause before doing another if wanted
if &delay_secs; > 0 then
wait.time (&delay_secs;)
end -- if pause wanted
end -- of iterating through each speedwalk line
-- all done!
ColourNote ("white", "blue", "Speedwalk done.")
speedwalk_thread = nil
end) -- end of coroutine
end -- function func_handle_speedwalk
If you want to actually get a new speedwalk string out of it you will have to do a little extra work, but the command stacking should go a fair way towards what you described. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|