Lua function in trigger from script

Post Reply
Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Lua function in trigger from script

Post by Knute »

Ok, I am currently in the process of setting up a name highlighter based on vadi's.

I have hacked that script so much, and found quite a few similarities in the code between the various formats.

So, I am setting up a table to keep the book keeping changes, and scripting the rest. It's also going to use the db functionality to save the results.

Anyway, I need to know how to set up the trigger for sending a lua function from a script.

I am trying to do it this way because, well, honestly, if I want to change something, or colors don't look right, or something, I don't want to have to dig into the code to do it. I want to make my changes in the table, reinitialize it, and be on my way.

Which means, that the scripts are writing the codes. So far, I have it set up to do the aliases necessary, and such, but I'm having trouble getting that one piece (saveline) to actually do the lua function. Without that line, it doesn't work.

So, how do I script a lua function into a trigger? All I have found is permBeginOfStringTrigger(), permRegexTrigger(), and permSubstringTrigger().

I have tried using the Regex, but do not know what to use for the lua table.

I know that I am using it correctly, because Lusternia only uses the "Total: " thing for enemies, for members and such, it has to be a regex to match the prompt.
Those go through ok. It's just when I put the saveline trigger in to have it added that I run into problems.

Any ideas?

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Lua function in trigger from script

Post by naftali »

Please, explain your question more clearly. Since it's very simple to call a function from a trigger, I assume you're asking how to create a trigger in a script that calls a lua function? If so this is how:
Code: [show] | [select all] lua
tempTrigger("substring to trigger on",[[luaFunction()]])

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Lua function in trigger from script

Post by Knute »

I need a permTrigger, so that it can be attached to a parent.
Ok, if I were doing it through the gui I would put "return true" in the match and select "lua function" from the type/dropdown list.

I want to do that same thing, but only from a script so that it will trigger after the parent.

Does that make sense?

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Lua function in trigger from script

Post by Vadi »

You can't make the pattern type be lua script yet (although a pattern of return true could quite easily be pre-created...)

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Lua function in trigger from script

Post by Knute »

How?

I have the saveline as a function, so all that will go into the script is the function call.

How do I "pre-create" this?

I'm not exactly sure what you are hinting at, but am interested.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Lua function in trigger from script

Post by Vadi »

Make a trigger in the editor, put the function you want to call in there, click save

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Lua function in trigger from script

Post by Knute »

Mrmmhrmmm... Kinda defeats the point of trying to automate the changes..... Thanks though.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Lua function in trigger from script

Post by Oneymus »

Knute, if you're just looking to manage permanent triggers through scripts, you can use the perm*Trigger functions.
Code: [show] | [select all] lua
permRegexTrigger( "this_trigger", "this_trigger_parent", { [[^Total:\s.*]], [[\d+h, \d+m]] }, [[saveline()]] )
I assume saveline() is a function you have defined elsewhere.

You can use the exists() function to check and see if the "this_trigger" trigger already exists, so you don't duplicate it.
Code: [show] | [select all] lua
exists( "this_trigger" )
You, have, also, the killTrigger() function to remove permanent triggers whenever you need to update the system.
Code: [show] | [select all] lua
killTrigger( "this_trigger" )
I think using the "Lua function" pattern in the trigger engine is not what you want. That expects either true or false as the return of whatever function you use in there. If you're adamant about using it, you could do something along the lines of...

In a script:
Code: [show] | [select all] lua
function doSaveline ()
    return do_saveline
end
Pattern: lua function: doSaveline()
Body: saveline()

do_saveline being a boolean (true/false) flag you set to decide whether or not to save. However, it's not very efficient, since it would be checking that every line; using the perm*Trigger functions would work better for you.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Lua function in trigger from script

Post by Vadi »

Small correction, I think it's
Code: [show] | [select all] lua
 exists( "this_trigger", "trigger" )

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Lua function in trigger from script

Post by Knute »

Oneymus wrote:Knute, if you're just looking to manage permanent triggers through scripts, you can use the perm*Trigger functions.
Code: [show] | [select all] lua
permRegexTrigger( "this_trigger", "this_trigger_parent", { [[^Total:\s.*]], [[\d+h, \d+m]] }, [[saveline()]] )
I assume saveline() is a function you have defined elsewhere.

You can use the exists() function to check and see if the "this_trigger" trigger already exists, so you don't duplicate it.
Code: [show] | [select all] lua
exists( "this_trigger" )
You, have, also, the killTrigger() function to remove permanent triggers whenever you need to update the system.
Code: [show] | [select all] lua
killTrigger( "this_trigger" )
I think using the "Lua function" pattern in the trigger engine is not what you want. That expects either true or false as the return of whatever function you use in there. If you're adamant about using it, you could do something along the lines of...

In a script:
Code: [show] | [select all] lua
function doSaveline ()
    return do_saveline
end
Pattern: lua function: doSaveline()
Body: saveline()

do_saveline being a boolean (true/false) flag you set to decide whether or not to save. However, it's not very efficient, since it would be checking that every line; using the perm*Trigger functions would work better for you.
Thanks. I already have that checking in place. I didn't know about the killTrigger option working on permTriggers though. Thanks for that.

What I'm trying to do is to rewrite Vadi's name highlighter. Since most of the code is repetitive for the various places that you could use it, I am attempting to have the triggers being written from common code, with a table where you can make your modifications.

So for instance, if you want your guild members to have a gold background, there would be no digging through code, just set gold for the background in the gmembers part of the table, and then update. Or if gold doesn't work after updating, you can change it to something else without changing the code, just the table.

Post Reply