Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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>
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 24, 2009 3:12 am   
 
zs.param(1) rather than %1.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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")
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: 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
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 24, 2009 11:49 am   
 
I made an error in that script; I've edited your post and mine to correct it.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net