help with triggering on a lua function

Post Reply
naoise
Posts: 6
Joined: Fri Sep 16, 2011 9:36 pm

help with triggering on a lua function

Post by naoise »

Ok so I am quite new to scripting and triggering and all that, but I am already stuck.

I made an alias varset which executes the lua code : var1 = 1

This works fine, but when I try to make a trigger to go off when var1 == 1, I have some trouble, as the trigger does not activate.

The full trigger is:

name: variablechange
0: if var1 == 1 then return true else return false end

in the script area:
var1 = 0
echo ("wewt it worked")

What am I doing wrong?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: help with triggering on a lua function

Post by Heiko »

Triggers are only processed when a new line has arrived from the MUD.

naoise
Posts: 6
Joined: Fri Sep 16, 2011 9:36 pm

Re: help with triggering on a lua function

Post by naoise »

ok I see. Is there some way using the scripting panel that I could force triggers to fire if ready to fire?

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: help with triggering on a lua function

Post by Manni »

you could always set the pattern in your trigger to 'return isPrompt()' the drop down would be lua function

the trigger script would be:
Code: [show] | [select all] lua
if var1 == 1 then echo("woohoo!") end
   var1 = 0
   disableTrigger("this trigger")
while the alias script would be:
Code: [show] | [select all] lua
var1 = 1
enableTrigger("this trigger")
"this trigger" would be changed to be the name of the trigger

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: help with triggering on a lua function

Post by Iocun »

In response to Manni's post: There's no real reason for doing that stuff. Why fire off prompt when you want to only fire when a certain variable is set? The trigger in the OP is the best way of doing this, except it will only fire when a line is received (but so will a prompt trigger).

And if you don't want to wait for a line to be received, you can't use triggers. Triggers are really only meant to fire on new input from the mud. If you want something to react to what you type, you use aliases. So use your alias directly to call a function/raise an event.

Manni
Posts: 116
Joined: Tue May 31, 2011 9:00 pm

Re: help with triggering on a lua function

Post by Manni »

I'm only firing off prompt to give an example of what a trigger can do, and thats a guaranteed line (plus it was the first thing that came to mind because I closing a gate trigger when I wrote the response at 3 in the morning).

a more practical example would be get gold when a creature drops it, or something that counts your kills for you.

to count kills you would have an trigger and a script.
Script:
Code: [show] | [select all] lua
mykills = 0
everytime you bootup mudlet mykills will = 0 by default


you trigger would look for a "beginning of substring" that would look like: You have slain
and the script would be:
Code: [show] | [select all] lua
mykills = mykills + 1 --so if mykills is 0, it is now 1
echo("You have killed "..mykills.." times.") 

Post Reply