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 ➜ Bug reports ➜ trigger sequence incorrect when using script file/internal script together

trigger sequence incorrect when using script file/internal script together

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


Posted by Zhenzh   China  (68 posts)  Bio
Date Wed 28 Aug 2019 12:55 PM (UTC)

Amended on Wed 28 Aug 2019 12:59 PM (UTC) by Zhenzh

Message
I have two triggers using the same tragger pattern.
Trigger A has a smaller sequence number and response from script file. And the trigger B has a bigger sequence number and response from internal script commands.

I expect the trigger A being executed before trigger B but the result is trigger B triggered first.

Here's my test result

local triggerA = {
    ["enabled"] = "y", 
    ["sequence"] = "50", 
    ["script"] = "seq_test", 
    ["regexp"] = "y", 
    ["name"] = "higher_priority", 
    ["keep_evaluating"] = "y", 
    ["match"] = "sequence test"
}

function seq_test()
    Note("higher_priority")
end

addxml.trigger(triggerA)


local triggerB = {
    ["enabled"] = "y", 
    ["send"] = "Note("lower priority")", 
    ["sequence"] = "200", 
    ["name"] = "lower_priority", 
    ["regexp"] = "y", 
    ["send_to"] = "12", 
    ["keep_evaluating"] = "y", 
    ["match"] = "sequence test"
}

addxml.trigger(triggerB)

---------------------------------------
test result:

trigger line: sequence test
lower priority
higher_priority

Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 28 Aug 2019 11:46 PM (UTC)
Message

See How MUSHclient processes text arriving from the MUD.

Things “sent to script” are done as they are processed (in sequence) however if your trigger mentions a script function, then they are deferred until later since the same trigger may match more than once.

Thus all “send to script” scripting is done before all “script file” scripting, regardless of sequence.

Either make everything “send to script” or move the “send to script” stuff into the script file.


- Nick Gammon

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

Posted by Zhenzh   China  (68 posts)  Bio
Date Reply #2 on Thu 29 Aug 2019 05:16 AM (UTC)

Amended on Thu 29 Aug 2019 05:18 AM (UTC) by Zhenzh

Message
I moved all process into script files and the execution sequence work as expected.
But still being troubled by status control of triggers.


function triggerA()
    Note("triggerA: now trigger b is "..tostring(GetTriggerInfo("triggerB", 8)))
    EnableTrigger("triggerB", false)
    Note("trigger a is executed, disabled trigger b")
    Note("triggerA: now trigger b is "..tostring(GetTriggerInfo("triggerB", 8)))
end

function triggerB()
    Note("triggerB: now trigger b is "..tostring(GetTriggerInfo("triggerB", 8)))
    Note("triggerB: trigger b is executed")
end

local triggerA = {
    ["enabled"] = "y", 
    ["sequence"] = "50", 
    ["script"] = "triggerA", 
    ["regexp"] = "y", 
    ["name"] = "triggerA", 
    ["keep_evaluating"] = "y", 
    ["match"] = "sequence test"
}

addxml.trigger(triggerA)

local triggerB = {
    ["enabled"] = "y",
    ["sequence"] = "200", 
    ["script"] = "triggerB", 
    ["regexp"] = "y", 
    ["name"] = "triggerB", 
    ["keep_evaluating"] = "y", 
    ["match"] = ".+"
} 

addxml.trigger(triggerB)
-----------------------------------------------
test result:

trigger line: sequence test
triggerA: now trigger b is true
triggerA: trigger a is executed, disabled trigger b
triggerA: now trigger b is false
triggerB: now trigger b is false
triggerB: trigger b is executed



I expect the triggerA(higher priority) can turn off the triggerB once it is triggered.
The actual result shows triggerA do be executed before triggerB and the status of triggerB do be changed. While the triggerB was still executed though it is inactive.

As the match pattern of triggerA needs to be used by some other triggers, so that I can not set "keep_evaluating" = "n" for triggerA
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 30 Aug 2019 09:23 AM (UTC)
Message

Yes, well as that link I posted says, triggers that call a script file are queued up and the scripts called after all triggers are processed. Thus, a script that tries to disable other triggers won’t work.

If you want a trigger to change the evaluation of the same line then you will have to use send-to-script.

However you don’t necessarily have to put all the script into the “send to” box. You can put the bulk of the script in the script file, and just call that from send-to-script, eg.

Now you put MyTriggerFunction into your script file, and it is called from send-to-script, which means it will be done during trigger evaluation, and you can disable other triggers. However you may need special processing if you are using wildcards. In that case you might have to pass the wildcards to your script function, eg.

That would pass the first three wildcards down to MyTriggerFunction.


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


14,951 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.