Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Message
| I've tried to do a speed walk that waits for exits a different way, to make it simpler. The alias below should accomplish that for you, providing you make Lua your scripting language, and the file "exampscript.lua" your script file (see the Scripts tab in the world configuration).
<aliases>
<alias
match="!*"
enabled="y"
send_to="12"
sequence="100"
>
<send>do local t = coroutine.create (function (t)
local lines = {}
sw = EvaluateSpeedwalk ("%1")
-- check for valid speedwalk
if string.sub (sw, 1, 1) == "*" then
ColourNote ("white", "red", string.sub (sw, 2))
return
end -- if
rex.new ("(.+)"):gmatch (sw,
-- build speedwalk lines into a table
function (m)
table.insert (lines, m)
end)
-- iterate the table, sending each line to the MUD
for i, line in ipairs (lines) do
-- send the speedwalk
Send (line)
-- now wait for an appropriate response
line, wildcards = waitforregexp (t,
"^(Exits: .*\.|Alas, you cannot go that way\.)$")
-- check we didn't get told it was impossible
if string.sub (line, 1, 5) ~= "Exits" then
ColourNote ("white", "red", "Speedwalk cancelled")
return -- give up
end -- if
end -- of iterating through each speedwalk line
-- all done!
ColourNote ("white", "blue", "speedwalk done")
end) assert (coroutine.resume (t, t)) end
</send>
</alias>
</aliases>
What this does is make an alias where you type "!" followed by the speedwalk string, and it then sends the lines one by one until the speedwalk is finished. It doesn't send a new line until an "Exits:" line arrives, thus making sure that each line is sent only when ready.
Eg. You type: ! 3e 2n
It also tests for the "error" message "Alas, you cannot go that way." and if received cancels the speedwalk, on the basis that you must have wandered into somewhere unexpected, and sending further speedwalks will be a waste of time.
If the "error" line is different you will need to change the line above to match what your MUD sends, escaping special characters like periods with a backslash, as is done above.
You may also need to modify the "Exits:" part above if your MUD sends something different, like "Obvious exits" or something similar.
[EDIT]
Modified to check for valid speedwalk string.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|