• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

2 units share 1 variable?

Status
Not open for further replies.
Level 4
Joined
Apr 26, 2011
Messages
65
Hi, i have 2 units, 2 regions and 2 triggers :ogre_love:

1) if unit enters region A1, set superunit = entering unit
2) if unit enters region A2 and if entering unit = superunit, then kill entering unit

c'mon guys, main problem is coming :goblin_jawdrop:

1) footman enters A1
2) peasant enters A1
3) footman enters A2 - and nothing happens cos peasant is superunit

CAN U HELP ME HOW TO KEEP BOTH UNITS IN VARIABLE superunit ???
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
A variable can only be allocated to 1 value at any time. Instead of trying to do something physically impossible with normal computing, you could try changing your code to match what is possible.

For this problem, I would advise a unit group. That is a complex structure that can be referenced from a variable which can reference multiple individual units nativly. Add the unit to the group when it enters region 1 and then when it enters region 2 you can test if it is in the group (for your condition). You must remember to remove the unit from the group when killing it as that is not done automatically and could eventually cause degraded performance of the group instance as well as handle index leaks.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
2 units can share the same variable for this case:

  • Can Share Variables
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Lightning
    • Actions
      • Set Units = (Triggering unit)
      • Unit - Set life of Units to ((Life of Units) + 100.00)
      • Set Units = (Target unit of ability being cast)
      • Unit - Set life of Units to ((Life of Units) - 100.00)
In this case, the trigger works perfectly

But you can't do this:

  • Cant Share Variables
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Lightning
    • Actions
      • Set Units = (Triggering unit)
      • Set Units = (Target unit of ability being cast)
      • Unit - Set life of Units to ((Life of Units) + 100.00)
      • Unit - Set life of Units to ((Life of Units) - 100.00)
This trigger works, but the set life action only occurs to last assigned variable, which is the (Target unit of ability being cast).

What you simply need to understand is, a variable will work for the last assigned data which will overwrite the last data and creates/saves a new one.

It depends on the the sequence of your trigger, really.
 
It's just a trigger that shows how to use 1 variable for different units to divide actions defskull.
This has nothing common with setting same variable for two different units because its impossible.

He has to use MUI techniques like Hash/Indexing or use Pick all units in group action already mentioned in this post by Maker DSG or rysnt11.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
2 units can share the same variable for this case:

  • Can Share Variables
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chain Lightning
    • Actions
      • Set Units = (Triggering unit)
      • Unit - Set life of Units to ((Life of Units) + 100.00)
      • Set Units = (Target unit of ability being cast)
      • Unit - Set life of Units to ((Life of Units) - 100.00)
In this case, the trigger works perfectly

They still are not sharing the variable. You simply assign it a value, use the value and then assign it a different value and use that value. Further more, you can use locals in this situation instead of a global to be more efficient.

It is just impossible for a variable to have 2 values at the same time. You can however use an array to store multiple values to a variable using an index (think of it as a group of variables).
 
Status
Not open for further replies.
Top