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:
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:
That happens because %1 is substituted with Fred, giving you:
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:
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. |