Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Problem with using a variable in script

Problem with using a variable in script

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


Posted by Mccane   (28 posts)  Bio
Date Fri 25 Jul 2008 08:16 AM (UTC)
Message
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?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 25 Jul 2008 09:28 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #2 on Mon 28 Jul 2008 11:57 AM (UTC)
Message
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
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.


14,580 views.

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

Go to topic:           Search the forum


[Go to top] top

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