[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Trigger/script execution order mixup?
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Trigger/script execution order mixup?

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


Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Sun 09 May 2004 06:37 PM (UTC)

Amended on Sun 09 May 2004 06:43 PM (UTC) by Ked

Message
In trying to make a small setup for channeling chat out of my output window and into a notepad one I stumbled upon something that surprised me - I use a prompt trigger with a sequence of 0 to disable a * trigger with a sequence of 1, and both triggers call the same script sub. It seems that this script is called only after all triggers have matched on a line, so the sequence 1 trigger is disabled already after it matches, even though it is being disabled by a trigger with sequence 0. Here's the actual setup:


<triggers>
  <trigger
   keep_evaluating="y"
   match="^[0-9]+h, [0-9]+m \D*?-.*$"
   name="chat_end"
   regexp="y"
   script="ChannelChat"
  >
  </trigger>
  <trigger
   match="^(.*)$"
   name="chat_middle"
   omit_from_output="y"
   regexp="y"
   script="ChannelChat"
   sequence="1"
  >
  </trigger>
  <trigger
   enabled="y"
   lines_to_match="2"
   match="^(?:[0-9]+h, [0-9]+m \D*?-|)([A-Z][a-z]+? (?:say|says), &quot;.*)$"
   name="chat_start"
   omit_from_output="y"
   regexp="y"
   script="ChannelChat"
   sequence="100"
  >
  </trigger>
</triggers>


And the script:


sub ChannelChat(name, output, wildcs)
	select case name
		case "chat_start"
			world.AppendToNotepad "Chat", wildcs(1) & vbCRLF
			world.EnableTrigger "chat_middle", 1
			world.EnableTrigger "chat_end", 1
		case "chat_middle"
			world.AppendToNotepad "Chat", wildcs(1) & vbCRLF
		case "chat_end"
			world.AppendToNotepad "Chat", vbCRLF
			world.EnableTrigger "chat_middle", 0
			world.EnableTrigger "chat_end", 0
	end select
end sub


The problem goes away if the prompt trigger sends its portion of the job to scripting, instead of calling the sub directly. This seems odd and I don't think it worked that way previously, though I might be wrong. In any case - the problem isn't major or immediate in this particular case, just wanted to clarify what is happening.
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 10 May 2004 07:13 AM (UTC)
Message
Triggers that call a sub have the sub calls queued, whereas "send to script" does it immediately. This was really done so that "omit from output" can omit the lines, and then the trigger scripts run, so that the world.note will add after the output is omitted. Also, if a trigger fires more than once on a line, the script is only called once.

Thus it would not surprise me if "send to script" ran before script subroutines.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Mon 10 May 2004 12:10 PM (UTC)
Message
So that is expected then? Okay. I guess it's not too much of a problem, since I can always just send to scripting as a workaround, and maybe use 2 triggers for the same line if I want to both omit the line from output and execute a script on it.
[Go to top] top

Posted by Shadowfyr   USA  (1,783 posts)  [Biography] bio
Date Reply #3 on Mon 10 May 2004 07:27 PM (UTC)

Amended on Mon 10 May 2004 07:30 PM (UTC) by Shadowfyr

Message
Hmm.. Interesting Nick. So a person could make one low numbered trigger using 'send to script' to read in the information for a line, then a second to omit it, but if you try to use a script to handle reading in the line before omitting it, it would fail, since it will have cleared the line before it is able to retrieve the styles and other information?

Not exactly consistent behaviour, but knowing that it behaves in such a manner, instead of more logically executing each trigger event as they happen, before testing against higher sequenced triggers is helpful. Knowing this you can trick the client into doing some things that are impossible otherwise, but it does introduce some interesting complications when you are not aware of it. In fact, for the above situation, you could have 'send to script' merely call a sub directly:

<send>call StoreLineInfo(getlinesinbuffer)</send>

so that the line you need is available for use when the omit trigger hits and calls its own sub to replace the original with a new one. Very interesting...
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 10 May 2004 09:59 PM (UTC)
Message
Ah yes, true.

This behaviour is why you cannot do world.Note in "send to script" in triggers that omit from output. The way it works is to omit from output from the start of the line that did the triggering, and if your notes happen to be on the end of that they get omitted too.

Thus, the sequence is, if a trigger matches:



  1. Play trigger sound if wanted.

  2. Do "send" stuff. Note that "send to output window" is actually queued into a string for later appending to the output window. However "send to script (or world etc.)" will be executed right now.

  3. Do any line colouring requested (ie. change triggered line colour).

  4. Queue up the name of the trigger script (if any).

  5. Log the trigger if wanted.

  6. Omit from the first trigger line to end of output buffer (if multiple-lines, eg. soft line breaks).

  7. Append any "send to output window" text saved in the earlier step to the output window in the current note colour.

  8. Execute trigger scripts queued up earlier.






- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


4,187 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]