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 ➜ Lua ➜ Triggers calling Lua functions

Triggers calling Lua functions

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


Posted by JoeScripter   (12 posts)  Bio
Date Sun 05 Nov 2006 04:29 PM (UTC)
Message
What is the accepted form for doing this?

I have set to working in converting a world file I started on a long time ago, to convert it from using perl scripts to lua.. In doing so, I have a couple of triggers which I used to call functions in my perl script file. I used regular expression triggers to be able to store certain text to pass as function parameters. The trigger would be set to "Send To: Script", and the "Send" box would be set to call the function along with the matching data (ie UpdateHP (%1, %2)). The label would be set to some arbitrary name for the trigger, and the "Script" field could be left blank.

This worked well, and this particular example (my UpdateHP function) seems to continue working as intended after porting UpdateHP to my lua script file. What doesn't make sense however is that I'm having problems porting another similar function (UpdateLevelAndClass). It's an almost identical trigger - in purpose and implementation - and yet for some reason my wildcard parameters aren't being passed.

The only way I've been able to get it to work is by setting "Script:" to my function name. In this case, the method gets called and the paramaters are the name of the function, the line that triggered it, and a table containing the wildcards which were created with the regex. Is this just how I'll have to do it? I sort of like the idea of being able to "Send to: Script", but can't seem to get parameters to consistently pass.

Any thoughts? :)
Top

Posted by JoeScripter   (12 posts)  Bio
Date Reply #1 on Sun 05 Nov 2006 04:32 PM (UTC)
Message
I've tested with an additional trigger set up to parse 2 wildcards through regex, and pass them to a function called Testing in my lua script. It seems that the wildcards don't get passed although if I change the Send: box from sending %1 and %2 to sending string literals, they pass just fine. Also, if I simply "Send to: Output", %1 and %2 get expanded into their wildcard match just fine.. this really doesn't make much sense to me :(
Top

Posted by JoeScripter   (12 posts)  Bio
Date Reply #2 on Sun 05 Nov 2006 06:33 PM (UTC)
Message
doh..!

I think I've gotten to the bottom of this. The difference in my testing regex vs the original regex which worked was that the original was matching numbers, whereas the newer regex's were matching numbers.. in other words..

This:
(Trigger Send field)
Testing (%1, %2)
resulted in the lua code:
Testing (Drunk, Hungry)

All I had to do was update my Send field to look like this:
Testing ("%1", "%2")
which translates to:
Testing ("Drunk", "Hungry")
- obviously what I was looking for originally..!

This is fascinating though, as it means that originally it was trying to pass in the contents of a variable named by the wildcard being passed.. ie the 'drunk' and 'hungry' variables, which were undefined and thus nil. Oh the possibilities..

Anyways, sorry for spamming :)
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.


12,561 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.