Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ I don't know why this isn't working...
|
I don't know why this isn't working...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Kaervos
USA (11 posts) Bio
|
| Date
| Sun 07 Sep 2008 06:46 PM (UTC) |
| Message
| Ok, so I have the following script:
function drink_health (name, line, wildcards)
if vitals.elixbal == 1 then
Send("DRINK HEALTH")
else
ColourNote("black", "white", "You will sip when the previous elixir clears your system.")
AddTriggerEx ("healwhenable", "You may drink another health or mana elixir.", "DRINK HEALTH", trigger_flag.Enabled + trigger_flag.KeepEvaluating, custom_colour.NoChange, 0, "", "autoheal_off", 0, 100)
end -- if
end -- function drink_health
This is supposed to keep me from inadvertantly wasting my health elixirs by drinking when they would be ineffective, instead creating a trigger that would make me drink the elixir when the game notifies me that I can do so. The trigger is supposed to delete itself by calling the function autoheal_off:
function autoheal_off (name, line, wildcards)
ColourNote("silver", "red", "Autoheal OFF")
DeleteTrigger ("healwhenable")
end -- function aheal_off
It sets up the trigger just fine, and when the trigger fires, it sends the ColourNote specified by the autoheal_off function, but it doesn't delete the trigger.
I also have an alias to call the autoheal_off function, and when I use the alias, the script functions properly, sending the note and deleting the trigger.
Why does the function autoheal_off delete the trigger when called by an alias, but not when called by the trigger it is intended to delete? | | Top |
|
| Posted by
| Worstje
Netherlands (899 posts) Bio
|
| Date
| Reply #1 on Sun 07 Sep 2008 07:18 PM (UTC) |
| Message
| To quote the manual for DeleteTrigger:
Quote: Description
Deletes the named trigger from the list of triggers.
WARNING - if the trigger is executing a script it cannot be deleted. For example, a trigger cannot delete itself.
If you need to delete a trigger from within itself use DoAfterSpecial to delete it after a short delay. You might also want to use EnableTrigger to disable it first.
An alternative you could use is to create the trigger normally, without AddTrigger(Ex), but make it disabled (enabled="n"). Instead of creating the trigger, you use EnableTrigger() to turn it on, and when it fires, you disable it again. | | Top |
|
| Posted by
| Kaervos
USA (11 posts) Bio
|
| Date
| Reply #2 on Sun 07 Sep 2008 08:58 PM (UTC) |
| Message
| | Okay, thank you very much! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Sun 07 Sep 2008 08:59 PM (UTC) |
| Message
| Another alternative is to make the trigger "one-shot" so it deletes itself once it fires. After creating the trigger, do this:
SetTriggerOption ("healwhenable", "one_shot", 1)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Kaervos
USA (11 posts) Bio
|
| Date
| Reply #4 on Sun 07 Sep 2008 09:50 PM (UTC) |
| Message
| | I don't think the one-shot trigger option was available in the version I was using. I got the updated version, and it works great! Thanks a bunch! | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
16,963 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top