Triggers calling Lua functions

Posted by JoeScripter on Sun 05 Nov 2006 04:29 PM — 3 posts, 13,229 views.

#0
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? :)
#1
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 :(
#2
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 :)