|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Fri Apr 24, 2009 1:26 am
Lua Trigger with a Regular expression pattern working with classes and variables |
Here is the output from the mud:
Code: |
| Keywords : mystical jade dragon sash Tao200Waist | |
Here is my regex LUA trigger. This Trigger does not work because of the [eqitem.keywords = %1] now if I make it do this instead [eqitem.keywords = "some words"] it works just fine. So I am not sure how your supposed to reference parts of the patern as variables eg: %1, %2, %3, etc from within a lua trigger... Also I am not sure how to enable or disable a class from within a lua trigger, with zscript it was #T+ classname or #T- classname, but I dont know how to do it with Lua. If I can figure these two things out I will have a fully functionally LUA based SQLITE equipment database system
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="5210" regex="true" language="Lua">
<pattern>^\| Keywords\s+: (.*).*\|$</pattern>
<value>eqitem = {}
eqitem.keywords = %1
print(eqitem)</value>
</trigger>
</cmud> |
|
|
|
|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Fri Apr 24, 2009 2:40 am |
If this is a limitation of the current state of cmud then I suppose I could write an Alias that is Lua and pass the variables to it as parameters, that stores the values that I need to store in a lua based table. and leave the trigger as zscript.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Apr 24, 2009 3:12 am |
zs.param(1) rather than %1.
|
|
|
|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Fri Apr 24, 2009 4:46 am |
oh I thought that was just for parameters didnt realize it worked for that as well. Thanks!
How about enable or disable a class? such as #T- classname and #T+ classname?
how would I do that from LUA?
This is the workaround I made for now incase anyone else comes across this thread, its a couple of zscript aliases classoff and classon:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="classoff">
<value>#T- %1</value>
</alias>
<alias name="classon">
<value>#T+ %1</value>
</alias>
</cmud>
|
then in a lua trigger or alias all you have to do is
zs.execalias("classon","class-name-here") or zs.execalias("classoff","class-name-here") |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Fri Apr 24, 2009 6:41 am |
Per Fang based on the same question you asked in this topic:
Fang Xianfu wrote: |
zs["t+"]("trigger id")
You could also use zs.gettrigger("trigger id") to return the object (and optionally save it somewhere, if you want to) and then edit its enable property directly, either:
zs.gettrigger("trigger id").enabled = false
or
trig = zs.gettrigger("trigger id")
trig.enabled = false |
Charneus |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Apr 24, 2009 11:49 am |
I made an error in that script; I've edited your post and mine to correct it.
|
|
|
|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Fri Apr 24, 2009 9:28 pm |
Thanks for the help guys, have my project nearly completed now! Will probably have it finished some time today.
|
|
|
|
|
|