Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Message
| Actually, it is easily done. Let me check what you want to achieve? I presume you wanted to make a whole lot of triggers like this...
Match: Someone stares at you, giving you the evil eye.
Omit from output: yes
Send: ColourNote ("white", "red", "Someone EVILEYES you.")
Send to script: yes
And so on. Your problem is, that the output does not appear, yes?
All you need to do is make a generic "stub" script (that goes in your script file), that simply defers the output slightly, then it appears. This is how I have done it and it works fine:
deferred_notes = {} -- table of things to be shown
-- show a deferred note - called from a trigger
function DeferNote (name, line, wildcards)
local k, v
for k, v in ipairs (deferred_notes) do
ColourNote (unpack (v))
end -- for looop
deferred_notes = {} -- done with table
end -- function DeferNote
-- add a deferred note to the table
function cn (...)
table.insert (deferred_notes, arg)
end -- function cn
This is in Lua, the recommended script language, however the same idea could be done in other languages.
What this does is maintain a table (array) of outstanding things to be sent to the output window (deferred_notes).
Instead of doing a ColourNote in the trigger you do "cn" instead (short for ColourNote, but less typing). This simply takes the arguments and puts whatever you planned to note into the table.
Then the trigger calls the script DeferNote which walks through the table, outputting each one using ColourNote, and then empties the table ready for next time.
Now your trigger looks like this:
Match: Someone stares at you, giving you the evil eye.
Omit from output: yes
Send: cn ("white", "red", "Someone EVILEYES you.")
Send to script: yes
Script: DeferNote
You can do multiple 'cn' calls from a trigger, as they just get appended to the table. The same line can match on multiple triggers and that will work OK too.
My exact triggers were:
<triggers>
<trigger
enabled="y"
match="Someone stares at you, giving you the evil eye."
omit_from_output="y"
script="DeferNote"
send_to="12"
sequence="100"
>
<send>cn ("white", "red", "Someone EVILEYES you.")
</send>
</trigger>
<trigger
enabled="y"
match="You feel a tightening sensation grow in your lungs."
omit_from_output="y"
script="DeferNote"
send_to="12"
sequence="100"
>
<send>cn ("black", "white", "Afflict : ", "white", "red", "ASTHMA")
</send>
</trigger>
<trigger
enabled="y"
match="You gasp as your fine-tuned reflexes disappear into a haze of confusion."
omit_from_output="y"
script="DeferNote"
send_to="12"
sequence="100"
>
<send>cn ("black", "white", "Afflict : ", "white", "red", "CONFUSION")
</send>
</trigger>
</triggers>
Once you have put the stub routines into the script file you can forget about them, and just do your line replacement inside the triggers themselves. That is easy enough to manage.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|