command to stop specific script?

Posted by Lotrex on Sat 17 Aug 2013 05:23 PM — 13 posts, 40,463 views.

#0
Yes, total noob here.

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)?
#1
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?
Australia Forum Administrator #2
Lotrex said:

Yes, total noob here.

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.
Australia Forum Administrator #3
Lotrex said:

Can something be written to change the reaction of task completion from north to east after x repetitions?


Yes, but perhaps if you post some code to show what you have in mind.
#4
Nick Gammon said:

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.

Quote:

<aliases>
<alias
match="rr"
enabled="y"
group="rootrun"
send_to="12"
omit_from_output="y"
sequence="100"
>
<send>

require "wait"

wait.make (function () --- coroutine below here

Execute ("forage")

local thistle = wait.regexp ("thistle", 100)
local none = wait.regexp ("nothing", 100)
local harvest = wait.regexp ("roots", 100)

if none then
Execute ("e")

Execute ("forage")

elseif thistle then
Execute ("e")

Execute ("forage")

elseif harvest then
wait.regexp ("clean", 300)

Execute ("e")

Execute ("forage")
end

local thistle = wait.regexp ("thistle", 100)
local none = wait.regexp ("nothing", 100)
local harvest = wait.regexp ("roots", 100)

if none then
Execute ("e")

Execute ("forage")

elseif thistle then
Execute ("e")

Execute ("forage")

elseif harvest then
wait.regexp ("clean", 300)

Execute ("e")

Execute ("forage")
end


end) -- end of coroutine

</send>
</alias>
</aliases>
Amended on Sun 18 Aug 2013 11:26 AM by Lotrex
Australia Forum Administrator #5

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
#6
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.

Here is what I now have for test purposes, works better than / as well as anything else I have tried:

Quote:

<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 == "thistle" then
Note ("D")

elseif what == "nothing" then
Note ("b")

elseif what == "root" then
Note ("c")

end -- if

end --if

Note ("z")

end) -- end of coroutine</send>
</alias>
</aliases>


The result is note "x", "forage" command sent, note "A", and note "z"

None of the second-tier(?) conditional triggers fire.
Amended on Mon 19 Aug 2013 04:17 AM by Lotrex
Australia Forum Administrator #7
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.
#8
Excellent. Thanks very much.

Is there a way to determine a command from line x that is not to be executed until after line x+n appears?

perhaps something like:

Quote:

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")
Send ("pull roots")
Execute ("alias for a command that creates a matching condition somehow")

end -- if

end --if

local line, what = wait.regexp ("picked clean", 100)

if previous unknown routine triggered by "root" executed
Send ("grind roots")
Note ("1")

end --if

Note ("z")

end) -- end of coroutine</send>



I'm still not clear on my original question.

something like this?

Quote:

Execute ("speedwalk5")

wait.regexp ("guard appears", 100)

if some sort of command then
return
Note ("aborting mission")

end -- if

Send ("bribe guard")

wait.regexp ("guard leaves",500)

if some sort of command then
return
Note ("aborting mission")

end -- if


Also, how can I preserve my indentations on this forum?
Amended on Tue 20 Aug 2013 02:05 AM by Lotrex
Australia Forum Administrator #9
Lotrex said:

Also, how can I preserve my indentations on this forum?


Code tags.

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
Australia Forum Administrator #10
Lotrex said:


Is there a way to determine a command from line x that is not to be executed until after line x+n appears?


What do you mean by a command? Something you type? Or something from the MUD?
#11
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.
Australia Forum Administrator #12
Well anything's possible. Trying to build that all into one long script might make things confusing.

One approach would be to simply have a trigger that detects what the NPC said, store that in a variable, and then access that variable when needed.