[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Parameters
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Parameters

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


Posted by tobiassjosten   Sweden  (79 posts)  [Biography] 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/
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] 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.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] 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.
[Go to top] top

Posted by tobiassjosten   Sweden  (79 posts)  [Biography] 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/
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] 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.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] 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.
[Go to top] 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.


5,540 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]