How would I go about having a 'kill-switch' for a running routine? Is there something I can set up in the script itself to respond to a given input with a cessation of that routine at that time (ie ready to be executed again without re-enabling)?
Also, I can't figure out how the non-timed wait commands work. I've read a handful of threads dealing with them, but apparently they are assuming knowledge I don't have yet.
Is it possible to have one triggergroup activated, and wait for a series of events (whether output from the MUD or commands input via the routine running and associated triggers) which will then switch the active groups?
Say I'm navigating an area and I want to go north three rooms, doing some actions in those rooms, then go east from there. Can something be written to change the reaction of task completion from north to east after x repetitions?
How would I go about having a 'kill-switch' for a running routine? Is there something I can set up in the script itself to respond to a given input with a cessation of that routine at that time (ie ready to be executed again without re-enabling)?
Er, well a script function can always "return" to exit that function, if that answers your question.
a script function can always "return" to exit that function, if that answers your question.
I'm so lost.
Would that mean putting an "elseif x than end" condition at every step which has any "wait" commands?
Turns out I don't even understand as much as I thought. This is an attempt at resource gathering. I have triggers to "harvest" when desired resources are found, and those work fine, as do the aliases set to "Execute" here, but I'm lost on how to use local variables. This script completes the initial command "forage," than does nothing else.
local thistle = wait.regexp ("thistle", 100)
local none = wait.regexp ("nothing", 100)
local harvest = wait.regexp ("roots", 100)
What that will do is wait for "thistle", and then wait for "nothing" and then wait for "roots".
You probably want something like:
local line, what = wait.regexp ("(thistle|nothing|roots)", 100)
if line then -- got something?
if what == "thistle" then
-- do a thistle
elseif what == "nothing" then
-- handle nothing
elseif what == "roots" then
-- handle roots
end -- if
end -- if
I made a mistake. You should test for wildcard 1, like the revised one below:
<aliases>
<alias
match="rr"
enabled="y"
group="rootrun"
omit_from_command_history="y"
send_to="12"
sequence="100"
>
<send>require "wait"
wait.make (function () --- coroutine below here
Note ("x")
Execute ("forage")
local line, what = wait.regexp ("(thistle|nothing|root)", 100)
if line then
Note ("A")
if what [1] == "thistle" then
Note ("D")
elseif what [1] == "nothing" then
Note ("b")
elseif what [1] == "root" then
Note ("c")
end -- if
end --if
Note ("z")
end) -- end of coroutine</send>
</alias>
</aliases>
Quote:
I'm not clear on the use of "local line, what" rather than "local what" but the former at least triggers on "if line then" but not on anything else.
A function call can return multiple values in Lua. So:
line, what = wait.regexp ("(thistle|nothing|root)", 100)
Returns two things: The matching line, and an array of wildcards. In this case they are all wildcard 1, so we test for that.
In this case, I mean something sent from the client to the MUD.
For example, getting a reply of "yes" or "no" from an NPC will determine if I want to go east or west, but either way, I have to kill it first.
I am asking if it is possible to build a routine that would, for this case, execute the proper direction based upon the response given, but wait to do so until the creature was dead.