scripting trigger wildcards

Posted by Aggressio on Wed 23 Mar 2005 01:33 PM — 3 posts, 20,479 views.

#0
For some reason the helpfiles weren't enough for me to understand how to get wildcards from triggers to a script.

The vbscript example didn't tell how to set up the actual trigger, and trying something similar in jscript didn't work at all.

Later noticed that having special characters in the wildcard somehow affected the script and led to problems.

Yet I spent hours to figure out the syntax, reading the help files and going through this forum.

So some examples of setting up different wildcard scripts might be useful. with the trigger-setups.

wildcards like .* and etc. and ofcourse how to use the stuff in a script. %0 %1 %2 ? if ideas for examples are needed perhaps something like script for adding up different types of coins in a purse, or translating a symbol line of [@###:...] into number where @=1000,#=100,:=10,.=0

perhaps some revision in the help-files would be nice too.

Russia #1
Trigger wildcards can be used in scripts in two different ways. If you use scripting from inside the trigger itself (by putting the script into the Send field and selecting Scripting for the "Send to" option) then you can reference the wildcards just as you normally would in a trigger:

say Hello, %1


where %1 will be substituted by whatever is in the first wildcard. With scripting, however, the wildcards are translated literaly, which could lead to problems if you don't take that into account. For example, if "Fred" is in your first wildcard and you want to send that wildcard through scripting, then the following will generate an error:

world.Send (%1)


That happens because %1 is substituted with Fred, giving you:

world.Send (Fred)


Fred is not a string here, since it's not quoted, so unless you have a variable named Fred, and it also happens to hold a string - you'll get an error. Instead you should do:

world.Send("%1")


Now Fred will be quoted, which makes it a string literal. Of course, not quoting %# is not really a mistake, since you could have a Fred variable, in which case no error would be generated.

If you are using the wildcards in a function inside a scriptfile, then your function should accept 3 arguments, which are in order of appearance:

-name (of the trigger that called the function)
-output (what is in the trigger's Send field)
-wildcards (a list of them)

Here, to get the first wildcard you'll simply get the first element of the wildcards list. For example, here's the Fred example in a script file:


function Fred(name, output, wildcs) {
   world.Send (wildcs(0));
}


I am not exactly sure if the first wildcard in Jscript is actually at index 0, might be 1.
Australia Forum Administrator #2
See GetTriggerWildcard.