I don't know why this isn't working...

Posted by Kaervos on Sun 07 Sep 2008 06:46 PM — 5 posts, 17,321 views.

USA #0
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?
Netherlands #1
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.
USA #2
Okay, thank you very much!
Australia Forum Administrator #3
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)


USA #4
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!