• 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.

[Trigger] Variable Array

Status
Not open for further replies.
Level 3
Joined
Apr 16, 2013
Messages
18
The units from Region Checkpoint 1 will be picked to move to Region Checkpoint 2 and so on.
My question is, will it be fine to use the same variable? or is it better to use multiple variable arrays for the unit?

Same Array/Variable
  • Events
    • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in (Units in Checkpoint 1 <gen>) and do (Actions)
      • Loop - Actions
        • Set unit[0] = (Picked unit)
        • Unit - Order unit[0] to Attack-Move To (Center of Checkpoint 2 <gen>)
    • Unit Group - Pick every unit in (Units in Checkpoint 2 <gen>) and do (Actions)
      • Loop - Actions
        • Set unit[0] = (Picked unit)
        • Unit - Order unit[0] to Attack-Move To (Center of Checkpoint 3 <gen>)
Multiple Array/Variable
  • Events
    • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in (Units in Checkpoint 1 <gen>) and do (Actions)
      • Loop - Actions
        • Set unit[0] = (Picked unit)
        • Unit - Order unit[0] to Attack-Move To (Center of Checkpoint 2 <gen>)
    • Unit Group - Pick every unit in (Units in Checkpoint 2 <gen>) and do (Actions)
      • Loop - Actions
        • Set unit[1] = (Picked unit)
        • Unit - Order unit[1] to Attack-Move To (Center of Checkpoint 3 <gen>)
 
Last edited:
Level 30
Joined
Nov 29, 2012
Messages
6,637
No it is really not fine to use same Variable Array because for example when you are doing a Random Hero Choose trigger, you have to keep each hero in a variable array and make a trigger that randomely chooses from those random variable array so when you make all the hero have same variable array, it will not work and leak maybe.
 
Level 30
Joined
Nov 29, 2012
Messages
6,637
If ur just ordering units in one region to attack move to another region u don't need an array. The array is useless here. Like I said above just use picked unit don't store picked unit into a variable.

Yes, I know jjust reminding him because in the future triggers he might do that involves like Random Hero triggers he might use the same method, same variable arrays. It just serves as a warning.:grin:
 
Level 3
Joined
Apr 16, 2013
Messages
18
U can just order picked unit to move the variable array is not needed. Also u have point leaks

So it should look something like this?
  • Events
  • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
    • Set Checkpoint 1 = (Center of Checkpoint 1 <gen>)
    • Set Checkpoint 2 = (Center of Checkpoint 2 <gen>)
    • Set Checkpoint 3 = (Center of Checkpoint 3 <gen>)
    • Unit Group - Pick every unit in Checkpoint 1 and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 2
    • Unit Group - Pick every unit in Checkpoint 2 and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 3
 
Last edited:
Level 20
Joined
Apr 14, 2012
Messages
2,901
So it should look something like this?
  • Events
  • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
    • Set Checkpoint 1 = (Center of Checkpoint 1 <gen>)
    • Set Checkpoint 2 = (Center of Checkpoint 2 <gen>)
    • Set Checkpoint 3 = (Center of Checkpoint 3 <gen>)
    • Unit Group - Pick every unit in (Units in Checkpoint 1 <gen>) and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 2
    • Unit Group - Pick every unit in Checkpoint 2 and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 3

Yes but you should do it like this:

Put the Units in Checkpoint 1 in a group variable so you don't leak.

  • Events
  • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
  • Set Group[1] = (Units in Checkpoint 1 <gen>)
  • Set Group[2] = (Units in Checkpoint 2 <gen>)
    • Unit Group - Pick every unit in Group[1] and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 2
    • Unit Group - Pick every unit in Group[2] and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 3
After this trigger or in some triggers after they have reached the end point (I don't know what your map is but you get the point) you should do this:

  • Clear Leaks
  • Events
  • Conditions
  • Actions
  • Custom Script - call RemoveLocation(udg_Checkpoint 1)
  • Custom Script - call RemoveLocation(udg_Checkpoint 2)
  • Custom Script - call RemoveLocation(udg_Checkpoint 3)
  • Custom Script - call DestroyGroup(udg_Group[1])
  • Custom Script - call DestroyGroup(udg_Group[2])
  • Custom Script - set udg_Group[1] = null
  • Custom Script - set udg_Group[2] = null
  • Custom Script - set udg_Checkpoint 1 = null
  • Custom Script - set udg_Checkpoint 2 = null
  • Custom Script - set udg_Checkpoint 3 = null
You can't put these in your original trigger because your trigger is periodical and it seems like it's not turned off at any point. By the time you are done using this trigger, run the actions of the above trigger to remove the point leaks.
 
Level 3
Joined
Apr 16, 2013
Messages
18
Yes but you should do it like this:

Put the Units in Checkpoint 1 in a group variable so you don't leak.

  • Events
  • Time - Every 2.50 seconds of game time
  • Conditions
  • Actions
  • Set Group[1] = (Units in Checkpoint 1 <gen>)
  • Set Group[2] = (Units in Checkpoint 2 <gen>)
    • Unit Group - Pick every unit in Group[1] and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 2
    • Unit Group - Pick every unit in Group[2] and do (Actions)
      • Loop - Actions
        • Unit - Order (Picked Unit) to Attack-Move To Checkpoint 3
After this trigger or in some triggers after they have reached the end point (I don't know what your map is but you get the point) you should do this:

  • Clear Leaks
  • Events
  • Conditions
  • Actions
  • Custom Script - call RemoveLocation(udg_Checkpoint 1)
  • Custom Script - call RemoveLocation(udg_Checkpoint 2)
  • Custom Script - call RemoveLocation(udg_Checkpoint 3)
  • Custom Script - call DestroyGroup(udg_Group[1])
  • Custom Script - call DestroyGroup(udg_Group[2])
  • Custom Script - set udg_Group[1] = null
  • Custom Script - set udg_Group[2] = null
  • Custom Script - set udg_Checkpoint 1 = null
  • Custom Script - set udg_Checkpoint 2 = null
  • Custom Script - set udg_Checkpoint 3 = null
You can't put these in your original trigger because your trigger is periodical and it seems like it's not turned off at any point. By the time you are done using this trigger, run the actions of the above trigger to remove the point leaks.

That was very helpful, thanks!
 
Status
Not open for further replies.
Top