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
➜ Question about sequence flag in a trigger
|
Question about sequence flag in a trigger
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Mon 15 Jan 2018 11:59 AM (UTC) |
| Message
| How can I understand the use of sequence flag in a trigger?
Does it force commands in different triggers run by fired sequence?
I have such question because of a puzzle in my mind.
For example,
There're 2 triggers, trigger A and B
The trigger A is fired first and the the trigger B is fired follow with trigger A
Trigger A executes a lot of commands which may spend some time and finally write the result to some value.
Trigger B directly overwrite the value to 0 which spend little time.
I wonder whether the write action of trigger B may be completed before trigger A completing its computing/writing?
I need a way to force all triggers completing their own actions by fired sequence.
fire sequence: triggerA,triggerB,triggerC ...
command sequence: triggerAcmd1,triggerAcmd2,triggerBcmd1,triggerBcmd2,triggerCcmd1 ... | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Mon 15 Jan 2018 08:44 PM (UTC) |
| Message
| | Make the one you want done first have a lower sequence (eg. 50). Also set it to "keep evaluating" so that the second trigger is also processed. If you do "send to script" then the scripts are called in the trigger evaluation order. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Reply #2 on Tue 16 Jan 2018 02:09 AM (UTC) |
| Message
| Will the higher sequence trigger wait until the lower sequence trigger completing all its sendto actions?
Besides, what's the use of "keep evaluation"? I tried check/uncheck it but get the same result. The trigger still fires every time.
I guess it may be the following effect:
Suppose I have
triggerA(seq 50), triggerB(seq 100)
fired sequence: triggerA, trigggerB, triggerA
If check keep evaluation, the sendto sequence will be:
triggerA sendto, triggerA sendto, triggerB sendto
If uncheck keep evaluation, it will become:
triggerA sendto, triggerB sendto, triggerA sendto
Am I correct? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 16 Jan 2018 02:23 AM (UTC) |
| Message
|
Zhenzh said:
Besides, what's the use of "keep evaluation"? I tried check/uncheck it but get the same result. The trigger still fires every time.
On a single line from the MUD it matches the triggers in sequence order (lowest first). If one matches the line, then it does not do any further matching unless "keep evaluating" is set, in which case it will keep processing further triggers.
On one line you will never get "triggerA, trigggerB, triggerA" because each trigger is only checked once, so I don't know why you are expecting that.
Perhaps if you paste your triggers here, see:
 |
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
|
Also copy and paste the text from the MUD that you are trying to match on. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Tue 16 Jan 2018 02:24 AM (UTC) |
| Message
| |
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Reply #5 on Tue 16 Jan 2018 05:33 AM (UTC) |
| Message
| I haven't had the code written as I'm just considering how to set the sequence of all may triggers.
My previous description may get you misunderstood what I mean. The example triggersA/B are all in different lines. Let me show you the exact concern I have as below:
Suppose the output is:
killer falls on the ground
killer dies
Trigger A:
matches: "* falls"
send: SetVariable("killerstat","fall")
Execute("look killer")
Trigger B:
matches: "* dies"
send: SetVariable("killerstat","die")
Execute("look corpse")
My expected order is:
SetVariable("killerstat","fall")
Execute("look killer")
SetVariable("killerstat","die")
Execute("look corpse")
My concern is that if the action of trigger B may be done before when action of trigger A is delayed from network issue or other reason, which may get an odd action order like:
SetVariable("killerstat","fall")
SetVariable("killerstat","die")
Execute("look killer") <- action of trigger A
Execute("look corpse")
So, my exact question is what's the condition of a trigger starting its action?
Is it the trigger matches the new line and all previous triggers completed their action OR just the trigger matches the new line? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #6 on Tue 16 Jan 2018 06:16 AM (UTC) |
| Message
| Each line is treated on its own. All triggers are executed (regardless of sequence number) before the next line is processed.
Thus, you will always get the "fall" trigger before the "dies" trigger.
Quote:
Is it the trigger matches the new line and all previous triggers completed their action OR just the trigger matches the new line?
Triggers don't "look ahead" to see if new lines are arriving. Each trigger matches on the current line, thus the triggers are executed in the order the lines arrive from the MUD.
Quote:
... when action of trigger A is delayed from network issue or other reason ...
The order you see things on the screen will be the order in which the triggers fire. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Reply #7 on Tue 16 Jan 2018 09:02 AM (UTC) Amended on Tue 16 Jan 2018 08:32 PM (UTC) by Nick Gammon
|
| Message
| Then, how is the running order between script and trigger?
I'm considering using combination of trigger+script to rewrite a robot which used to be implemented by script only.
The original script looks like:
function dojob()
wait.make(function()
Execute("kill killer")
local l,w = wait.regexp("killer (\\S+) ",10)
if w == "dies" then
print("job done")
end
end)
end
I'd like to use a trigger to auto refresh states instead of using wait.regexp to capture wildcard.
The modified script looks like:
function dojob()
wait.make(function()
Execute("kill killer")
wait.regexp("killer dies",10)
if GetVariable("killerstat") == "die" then
print("job done")
end
end)
end
Trigger
matches: "killer dies"
send: SetVariable("killerstat","die")
When the output "killer dies" come to the window, I wonder who has higher priority to be run first, the SetVariable action in trigger or the GetVariable action in script?
You mentioned the script sequence related to the trigger/alias who invoke the script.
Then, how about the script directly invoked from mush command line or loaded by default at the beginning of the world? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #8 on Tue 16 Jan 2018 08:41 PM (UTC) Amended on Tue 16 Jan 2018 08:42 PM (UTC) by Nick Gammon
|
| Message
| The function wait.regexp is implemented by making a temporary one-shot trigger. You can see that in the code for wait.lua, around line 106. That file is in the "lua" subdirectory of the MUSHclient installation.
If you specify a time-out then it also creates a temporary one-shot timer for the specified time.
So, your original script has paused in a coroutine, waiting for that temporary trigger (and possibly timer) to fire. When it fires (or 10 seconds are up in your case) then the trigger resumes the coroutine.
Now the question is, which trigger will fire first? The coroutine one, or the other one you mentioned that sets the variable? Well, the sequence number determines that, and wait.regexp sets a default sequence number of 100 (see line 121 in wait.lua).
If your other trigger has a lower sequence number (eg. 90) then it will set the variable first. If it has a higher sequence number (eg. 110) then dojob function will resume first. If it has the same sequence number (that is, 100) then the order of execution is undefined. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Zhenzh
China (68 posts) Bio
|
| Date
| Reply #9 on Wed 17 Jan 2018 01:44 AM (UTC) |
| Message
| Thank you for your explain.
Your answer do helps me understanding the sequence of trigger and scripts | | 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.
34,126 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top