Trigger delay

Posted by Jacob_P on Wed 24 Nov 2010 11:35 AM — 13 posts, 53,643 views.

#0
Im a new on using Mushclient and I like it alot. I have an irritating problem tho.
How do I create a trigger that fires after 2-5 secs randomly ?
I know I have to make a script for it but I have no idea what it shall look like and how to link it to a trigger.

I have a simple pattern I want it to trigger on, eg. " (playername) is hurt"
I then want the trigger to send "heal (playername)" to world, preferably at a random time from 2-5 seconds !

I hope someone can help me out with this !

Regards
Jakob
USA #1
DoAfter(math.random(4)+1, "heal %1")
#2
Okay, thanks ! But how do I implement this into my trigger ?
USA #3
Well, it's a script call, so first you need to make sure the trigger is set to Send to Script. Now lets look at the problem you have: You want a trigger that delays its action, right? So you use a script function that does stuff later. That's what DoAfter does: it takes an amount of time (in seconds), and something to send. Behind the scenes, it creates a temporary timer (which you can look at in the timers list if you're fast enough).

In other words, just paste what I gave you into the send box, and make sure you're sending to script.
#4
Okay!
So I will simply create a empty script named whatever I want and let the trigger send that piece of code to the script that executes it?
USA #5
I didn't understand that at all. ^_^ Give it a try and if it doesn't work, paste what you have for us to dissect. It's always easier to work with the code directly. :)

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#6
Im confused :p
, I have nothing to share :-) thats why I wrote here! I have no script and no trigger! I know how to create a trigger, thats simple, but I dont know how to create the script itself and make the trigger run the script when the MUD says "you are hurt" !
USA #7
Jacob_P said:
Im confused :p
, I have nothing to share :-) thats why I wrote here! I have no script and no trigger!

I know, I was hoping you might be able to try it yourself after my help before, and maybe come back with some more insight into the problem even if you didn't succeed. But no matter. :)

Jacob_P said:
I know how to create a trigger, thats simple, but I dont know how to create the script itself and make the trigger run the script when the MUD says "you are hurt" !

That's the easy part. Do you see the big text box in the trigger editing dialog? It says "Send:" to the left. Just paste the script above into that. Now do you see right below that, a dropdown box with "Send to:" to the left? Click it and select "Script".

What I think you're getting confused by is the "Script" field further down in the dialog. I'm not talking about that. It's useful, but not terribly different. The major difference is that you would put the name of a function to call in that field, and create the function somewhere else (likely in your script file). But again, this is not what I'm asking you to do. :)
Amended on Thu 25 Nov 2010 11:25 AM by Twisol
#8
Yeah, thats what I tried but it aint working at all !
#9
Jacob_P said:

Yeah, thats what I tried but it aint working at all !



I take that back :D
Its working, thanks for the help, i think im getting the hang of it !
#10
Hey guys. I had the same question Jacob did and exactly his questions and level of understanding and the good replies here got me squared away. Many thanks!

FWIW, I might have figured out the "Send to" dropdown if the option was "Script Engine" instead of "Script". Just seeind script there made me think the contents of that big text area would be passed a a script that you needed to specify in that "Script" field below.

I'd like to put a little note somewhere in there telling me what that script's supposed to do. I suppose the best way to do that is in the scripting lang itself? Use whatever comment mechanism it provides?

Which scripting language is this in anyway? Is that a line of LUA?

Australia Forum Administrator #11
Giddeon said:

I'd like to put a little note somewhere in there telling me what that script's supposed to do. I suppose the best way to do that is in the scripting lang itself? Use whatever comment mechanism it provides?

Which scripting language is this in anyway? Is that a line of LUA?


Yes, it's Lua - the recommended script language. (Lua not LUA).

I would use comments to explain what you are doing - I usually comment heavily because you never know when you will next pick up something and wonder what the heck you were doing. In Lua single-line comments are introduced with two hyphens, eg.


-- this is a comment


And multiple-line comments with two hyphens and two brackets, eg.



--[[
 this is a multi-line comment
 and so is this
--]]


#12
I've never seen those characters used for commenting. I've just skimmed a bit of Lua's history from Wikipedia.
Looks like I'll get to do a little mudding and add another language to the resume all at the same time!
Wonder if I can work a tax exemption in there somehow...

Thanks a ton Nick. I'm loving this client.