trigger sequence incorrect when using script file/internal script together

Posted by Zhenzh on Wed 28 Aug 2019 12:55 PM — 4 posts, 17,299 views.

China #0
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

Amended on Wed 28 Aug 2019 12:59 PM by Zhenzh
Australia Forum Administrator #1

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.

China #2
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
Amended on Thu 29 Aug 2019 05:18 AM by Zhenzh
Australia Forum Administrator #3

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.

MyTriggerFunction ()

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.

MyTriggerFunction ("%1", "%2", "%3")

That would pass the first three wildcards down to MyTriggerFunction.