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.
Entire forum
➜ MUSHclient
➜ Lua
➜ Parameters
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| tobiassjosten
Sweden (79 posts) Bio
|
Date
| Mon 25 Apr 2005 09:30 AM (UTC) |
Message
| I found a LUA function on these forums, which looked like this:
function mytrigger (name, line, wildcards)
Note ("In trigger ", name)
Send ("go ", wildcards.where) -- follow him
Send ("kill ", wildcards.who) -- attack him again
end
Now I'm wondering, where do you set those parameters (name, line, wildcards)? Are they just fetched from the trigger? What additional info can you include? |
Simplicity is Divine | http://nogfx.org/ | Top |
|
Posted by
| Tsunami
USA (204 posts) Bio
|
Date
| Reply #1 on Mon 25 Apr 2005 02:55 PM (UTC) |
Message
| this function is apparently called by a trigger using the script tag in xml..
<trigger
...
script="..."
...
></trigger>
MC then automatically calls the function nameed in the tag, and sets name to the name of the trigger, if any, line to the entire line that was matched, and wildcs to an array that contains any wildcards that were matched by a regular expression. | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #2 on Mon 25 Apr 2005 03:56 PM (UTC) |
Message
| Script functions called by triggers (and aliases) get three parameters. The name of the trigger that called it, the line that the trigger matched on, and then an array (or the equivalent in whatever language youre working with) of the wildcards.
Likewise, Timers are only send the timername (since there are no wildcards or lines).
Those are just the parameters of any script function that you want to use via the 'script' field (the script function to execute with a given trigger/alias/etc). |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | Top |
|
Posted by
| tobiassjosten
Sweden (79 posts) Bio
|
Date
| Reply #3 on Mon 25 Apr 2005 04:57 PM (UTC) |
Message
| I see, thanks. Could I skip out on using some parameters too? Like:
function mytrigger (line)
Would the line-parameter be set to the name of the trigger in that example? Eg, is the parameters represented in that function by their name, or their order? |
Simplicity is Divine | http://nogfx.org/ | Top |
|
Posted by
| Larkin
(278 posts) Bio
|
Date
| Reply #4 on Mon 25 Apr 2005 06:05 PM (UTC) |
Message
| You need all three parameters for the function to execute properly. I've seen people using triggers to call script functions and ignoring all three parameters completely, which I find pointless since they should have just called the script function from the body of the trigger command and done it the right way. | Top |
|
Posted by
| Flannel
USA (1,230 posts) Bio
|
Date
| Reply #5 on Mon 25 Apr 2005 07:50 PM (UTC) |
Message
| The parameters are nameless, like all other languages with subroutines.
Unlike other languages (where you have to match function names and argument lists), Lua doesn't care what the function's arguments looks like, it could have one argument, or five. Mushclient will always pass three, if you have only one argument in your function definition, then that will become the name, and the rest of the passed arguments will be discarded. If you have five, then your first three will be the name, the line, and the wildcards, and then your fourth and fifth would be nil.
So, if you just wanted the line, you'd need two parameters, one for the name, the second for the line. |
~Flannel
Messiah of Rose
Eternity's Trials.
Clones are people two. | 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.
20,925 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top