• 🏆 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!

Will multiple instances of this trigger overwrite data in the same variable?

Status
Not open for further replies.
Level 3
Joined
Feb 27, 2011
Messages
39
Now this could be a dumb question but,
I'm making a blocking trigger that goes like the following:
A unit is attacked
If unit has item SHIELD
then silence unit (dummy caster)
then play unit's defend animation
then set charges in SHIELD to -1
then set VARIABLE1 to charges in SHIELD

and another trigger:
A unit is attacked
If unit has item SHIELD
If VARIABLE1 equal to 0
then destroy SHIELD from triggering unit

What im asking is if multiple units will have item SHIELD and are being attacked say one has 20 charges and the other 50 then will they be overwriting each others data in VARIABLE1 ?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,223
Ofcourse they will. VARIABLE1 is a global and as such it will hold the value that it was assigned to last.

You can eithor use some complex index array system to get a unique index for each unit or use hashtables to attach the value to the unit (well use the handle ID of the unit as an index in the hashtable for the data).
 
Level 3
Joined
Feb 27, 2011
Messages
39
I have incorporated the second trigger into the first. The point is that a unit first sets the shield charges to a number, THEN the variable to the charges and THEN checks whether to destroy the item. Might this work out or would the overwriting still be a problem?
  • Woodenshield blocking trigger incorporated
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Random integer number between 1 and 100) Less than or equal to 50
      • ((Triggering unit) has an item of type Round Wooden shield) Equal to True
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Attacking unit) is A melee attacker) Equal to True
        • Then - Actions
          • Item - Set charges remaining in (Item carried by (Triggering unit) of type Round Wooden shield) to ((Charges remaining in (Item carried by (Triggering unit) of type Round Wooden shield)) - 1)
          • Animation - Play (Triggering unit)'s defend animation
          • Unit - Order Dummy caster 0006 <gen> to Neutral Dark Ranger - Silence (Position of (Triggering unit))
          • Set Woodenshieldcharges = (Charges remaining in (Item carried by (Triggering unit) of type Round Wooden shield))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Woodenshieldcharges Greater than or equal to 1
            • Then - Actions
              • Do nothing
            • Else - Actions
              • Item - Remove (Item carried by (Triggering unit) of type Round Wooden shield)
        • Else - Actions
          • Animation - Play (Triggering unit)'s walk defend animation
If one unit would set charges to 0 his trigger would then destroy the item before another unit wold reset the variable to his own charges, ...or would it?
 
Level 3
Joined
Feb 27, 2011
Messages
39
I have perishable set to true, however when charges are set with triggers it wont perish.
get rid of the position leak.
Is this correct?
  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Set silencedUnitTemppoint = (Position of (Triggering unit))
      • Custom script: call RemoveLocation( udg_silencedUnitTemppoint )
Thanks for all help.
 
Status
Not open for further replies.
Top