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

Picked Unit After Set Unit Group Variable - better way to do this?

Status
Not open for further replies.
Level 21
Joined
Mar 16, 2008
Messages
955
Is there a better way to do this?
  • Trigger
    • Events
      • x
    • Conditions
      • y
    • Actions
      • Custom script: call DestroyGroup(udg_Units_Yellow)
      • Set VariableSet Units_Yellow = (Units owned by Player 5 (Yellow).)
      • Unit Group - Remove Yellow_Hero from Units_Yellow.
      • Unit Group - Remove Unit_Yellow_Altar from Units_Yellow.
      • Unit Group - Pick every unit in Units_Yellow and do (Unit - Change ownership of (Picked unit) to Player 21 (Coal) and Change color)
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,869
picked units does not create a Unit Group Object[?] because it's set to a variable and not something like <(Units owned by Player 5 (Yellow).)>

so, no need to do <set bj want destroy trigger> or anything further besides call DestroyGroup?

is that right?
Yes, that's correct. With this setup the Variable creates the Unit Group instead of the Pick Every Unit function.

The only way to keep track of and later on Destroy a newly created Unit Group is if you store it as a Variable. If you create the Unit Group inside of the Pick Every Unit function like so:
  • Unit Group - Pick every unit in (Units owned by Player 5) and do...
Then you won't have access to the Unit Group (Units owned by Player 5) and you won't be able to Destroy it.

Note that Setbjwantdestroygroup is just another method used for destroying Groups. It's not as safe as using a Variable though so I'd avoid using it.
 
Last edited:
Level 21
Joined
Mar 16, 2008
Messages
955
Thank you all!

@Uncle - you could destroy the picked unit group not set to a variable with the <set bj want destroy variable> command? but no other way?

@Razorclaw_X - call DestroyGroup will delete the Global Variable Object, making it unable to be set again? also potentially causing a game crash if a later trigger tries to set a variable that's been destroyed? So in this case I NEED to do Clear group, and NOT Destroy group.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,869
Thank you all!

@Uncle - you could destroy the picked unit group not set to a variable with the <set bj want destroy variable> command? but no other way?

@Razorclaw_X - call DestroyGroup will delete the Global Variable Object, making it unable to be set again? also potentially causing a game crash if a later trigger tries to set a variable that's been destroyed? So in this case I NEED to do Clear group, and NOT Destroy group.
You can either Fill/Clear the group or Create/Destroy the group. Create/Destroy is perfectly fine and it's what you'll see used majority of the time in GUI triggers like yours.

Although, unless I'm mistaken, this line of code will ALWAYS create a new unit group:
  • Set VariableSet Units_Yellow = (Units owned by Player 5 (Yellow).)
So the Fill/Clear method would leak a Unit Group each time the trigger runs beyond the first.

Also, you can't destroy a "global variable object" through code. What you can do is destroy the thing that it's pointing to.

And <set bj want destroy> can be set to True which will tell the next group creating function to destroy the group when it's finished. But there's a lot of posts on Hive about people having issues with it, so I wouldn't use it unless you're certain it's safe.
 
Last edited:
Status
Not open for further replies.
Top