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

Is this proper use of UnitGroup?

Status
Not open for further replies.
Level 4
Joined
Jul 20, 2012
Messages
83
So I've read over the tutorial about leaks and finally got myself into reworking my leaky triggers...
As the tutorial stated there are black-listed functions that should be avoided at all costs, what I mean is storing the group of units of type.

  • UnitGroup
    • Events
    • Conditions
    • Actions
      • Set TempUnitGroup = (Units of type Wandering Merchants)
      • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
        • Loop - Actions
          • Neutral Building - Add |c00959697Ring of |cffff0000Strength|r to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add |c00959697Ring of |cff18be00Agility|r to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add |c00959697Ring of |cff0000ffIntelligence|r to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add |c00959697Ring of |cffffcc00Power|r to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_Recipe_Common[(Random integer number between 1 and 8)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_Recipe_Epic[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_Recipe_Legendary[(Random integer number between 1 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_Orb[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_LQ_Armor_Weapon[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_LQ_Armor_Weapon[(Random integer number between 6 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
          • Neutral Building - Add Random_HQ_Armor_Weapon[(Random integer number between 1 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
      • Custom script: call DestroyGroup(udg_TempUnitGroup)
- so storing the units of type is a No-no... then I was wondering how can I do this without use of units of type...

  • UnitGroup
    • Events
    • Conditions
    • Actions
      • Set TempUnitGroup = (Units owned by Neutral Passive)
      • Unit Group - Pick every unit in TempUnitGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to Wandering Merchants
            • Then - Actions
              • Neutral Building - Add |c00959697Ring of |cffff0000Strength|r to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add |c00959697Ring of |cff18be00Agility|r to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add |c00959697Ring of |cff0000ffIntelligence|r to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add |c00959697Ring of |cffffcc00Power|r to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_Recipe_Common[(Random integer number between 1 and 8)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_Recipe_Epic[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_Recipe_Legendary[(Random integer number between 1 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_Orb[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_LQ_Armor_Weapon[(Random integer number between 1 and 5)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_LQ_Armor_Weapon[(Random integer number between 6 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
              • Neutral Building - Add Random_HQ_Armor_Weapon[(Random integer number between 1 and 10)] to (Picked unit) with 1 in stock and a max stock of 1
            • Else - Actions
      • Custom script: call DestroyGroup(udg_TempUnitGroup)
- can I use it like this? Storing the units of player and THEN filtering the type via conditions in the loop???
 
Level 4
Joined
Jul 20, 2012
Messages
83
One last question sir, does stuff leak when I use position of unit that is already in the map? I mean I have Circles of Power put in the map, do I have to store locations of their positions and then do all the procedure of removing the leak? Because as I understand it the location of something is another created region underneath it...
 
position / center / offset always leak unless properly taken care of.

u only have to remove the location if ur done with it.
example: if u have player start locations for players 1 to 12 and u store them in an array with the players number then u use that throughout the whole map it wont leak.
A leak is caused by overwriting the variable u use to point to the data.
This leaks because u overwrite the data b4 removing the leak
  • Set tempPoint = (Position of ( unit))
  • Set tempPoint = (Position of ( unit2))
  • Custom script call RemoveLocation( udg_tempPoint)
This doesnt leak because u remove the data b4 changing the variable.
  • Set tempPoint = (Position of ( unit))
  • Custom script call RemoveLocation( udg_tempPoint)
    • Set tempPoint = (Position of ( unit2))
  • Custom script call RemoveLocation( udg_tempPoint)
This doesnt leak because u arent creating a new point and u arent overwriting the variable.
  • Set tempPoint = (Position of ( unit))
  • move unit to tempPoint
  • create unit at tempPoint
  • // and so on
  • Custom script call RemoveLocation( udg_tempPoint)
 
Level 4
Joined
Jul 20, 2012
Messages
83
Oh I forgot, these two are about to be the last time :D
1.) If I have regions placed in the map and I use periodic spawning of units at center of one region, does the part "at the center of region" create new location point aswell? So it basically means I can store that point one time at initialization and use just the refference to it?
2.) I noticed that there are functions that revive Hero or move unit or anything else but the location doesn't have to be center of anything it's just Player Start Location, does PSL cause leaks even there doesn't seem to be any position (center, offset, point) of something just PSL?
 
Level 16
Joined
Jul 31, 2012
Messages
2,217
1) like dimf said :
position / center / offset always leak unless properly taken care of.
so you will have to store it and then clean it
2) it will leak, and again, like dimf said:
example: if u have player start locations for players 1 to 12 and u store them in an array with the players number then u use that throughout the whole map it wont leak.


EDIT: Yay, Death, you were faster :p
 
Status
Not open for further replies.
Top