• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Destroying Special Effect

Status
Not open for further replies.
Level 11
Joined
Nov 25, 2014
Messages
526
Hey hivers, I have this trigger that shows special effects when a coinbox is destroyed. The designated variable for such special effect is "specialeff[3]".
  • Makhutha Gateway Coinbox
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Dying unit)) Equal to Coin Box
    • Actions
      • Player - Add (Random integer number between 9 and 17) to Player 1 (Red) Current gold
      • Special Effect - Create a special effect attached to the origin of (Attacked unit) using UI\Feedback\GoldCredit\GoldCredit.mdl
      • Set specialeff[3] = (Last created special effect)
      • Special Effect - Destroy specialeff[3]
Alright, my concern is, after destroying specialeff[3], can I reuse this specialeff[3] again for other types of special effect?
 
Level 22
Joined
Aug 27, 2013
Messages
3,973
  • Special Effect - Create a special effect attached to the origin of (Attacked unit) using UI\Feedback\GoldCredit\GoldCredit.mdl
Attacked unit is not the correct response for your trigger event. Use dying unit or killing unit.

You don't really need to store your that special effect into variable but well, it's okay.

For the question, yes, you can re-use the variable again for the other types of special effect with condition it won't get replaced by something else before it gets destroyed. In its current state, I'm not so sure because I think it's unsafe.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
Alright, my concern is, after destroying specialeff[3], can I reuse this specialeff[3] again for other types of special effect?
You are not destroying the variable, you are destroying its contents. The variable can be reassigned to new special effects as much as you want, however do remember to eventually destroy them all to prevent leaks.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
In case you have another trigger with loop and the same variable is assigned there but during the loop, coin box dies and the event fires. It might mess up the other trigger. That's just my hypothesis because I haven't tried it in-game. That's why I think it's unsafe.
Unsafe is probably the wrong word.

A race condition can occur in global variables due to one thread yielding for another thread. For example if a trigger thread uses the global variable index 3 to store a special effect and then deals enough damage to kill the box. That trigger thread will yield to run an on death trigger thread which will overwrite the contents of the variable with another effect which gets destroyed before returning control back to the original thread. The original thread might then try to destroy the effect but fail to do so as the reference to it was lost.

The correct solution is to use local variables rather than global variables. This requires using JASS directly. Local declared local handle variables must also be assigned null before function return to prevent a possible handle counter reference leak due to a JASS bug.
 
Status
Not open for further replies.
Top