Problem with using a variable in script

Posted by Mccane on Fri 25 Jul 2008 08:16 AM — 3 posts, 18,800 views.

#0
Hola. In the game, there are note boards, and I am trying to count how many posts each poster has made. When do you something like 'note list' you'll see something like this:

Title of Post - Poster 12:00am Mar 20 '08
Title of Post2 - Poster2 12:00am Mar 20 '08
Title of Post3 - Poster3 12:00am Mar 20 '08

and on and on, hundreds of posts. So I wrote this regexp match line:

^(.*?)\- (?P<name>.*?) (.\d)\:(.*?)$

(^ ghetto, I know. I'm not very good with regexp)

to capture the name of the person. However, when I try to use Send to Script in the trigger to manipulate the variable, add it something, et cetera, using variable %2 or %<name> returns 'nil'. But if I change SEND TO to Output, put %2 or %<name> it will return the appropriate string, not 'nil'. For example, if I set it to Send to Script, and just type in the send box:

Note(%2)
or print(%2)
or
Note(%<name>)

it returns a note stating 'nil' when I test the trigger.

But if I set Send to Output and put just '%2' in the Send box, it'll print the name of the person correctly. Any ideas what I'm doing wrong?
Australia Forum Administrator #1
If you use a script file, then %1 and so on will not be expanded, as the script has already been compiled. Take a look at the examples in http://mushclient.com/scripting - inside a script function you get an array of wildcards.

For example:


function mytrigger (name, line, wildcards)

  Note( wildcards [2] )

end -- function


That would print wildcard number 2.
#2
Putting the script in the value box, however, is what he's doing. You just need quotes around your wildcards to make them expand as strings rather than Lua variables.

Note("%1") -- Should work fine
Note(%1) -- If %1 is Poster1, the script tries to access the Lua variable (not MUSHclient world variable) named Poster1 and doesn't find it, thus you get nil instead