Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ command to stop specific script?

command to stop specific script?

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Lotrex   (6 posts)  Bio
Date Sat 17 Aug 2013 05:23 PM (UTC)
Message
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)?
Top

Posted by Lotrex   (6 posts)  Bio
Date Reply #1 on Sat 17 Aug 2013 06:05 PM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Sun 18 Aug 2013 04:51 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Sun 18 Aug 2013 04:52 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lotrex   (6 posts)  Bio
Date Reply #4 on Sun 18 Aug 2013 11:19 AM (UTC)

Amended on Sun 18 Aug 2013 11:26 AM (UTC) by Lotrex

Message
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>
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 18 Aug 2013 10:51 PM (UTC)
Message

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lotrex   (6 posts)  Bio
Date Reply #6 on Mon 19 Aug 2013 04:15 AM (UTC)

Amended on Mon 19 Aug 2013 04:17 AM (UTC) by Lotrex

Message
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #7 on Mon 19 Aug 2013 10:39 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lotrex   (6 posts)  Bio
Date Reply #8 on Tue 20 Aug 2013 02:02 AM (UTC)

Amended on Tue 20 Aug 2013 02:05 AM (UTC) by Lotrex

Message
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?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #9 on Tue 20 Aug 2013 10:42 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #10 on Tue 20 Aug 2013 10:43 PM (UTC)
Message
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?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lotrex   (6 posts)  Bio
Date Reply #11 on Tue 20 Aug 2013 11:23 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #12 on Wed 21 Aug 2013 11:06 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


38,448 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.