• 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] Question about groups

Status
Not open for further replies.
Level 12
Joined
Mar 23, 2008
Messages
942
I'm trying to create a small group system to my spell, but I would like to know somethings:

- When I use DestroyGroup() what happens with the group?
- What is the difference between DestroyGroup() and GroupClear()?
- If I destroy a group I need to create it again with CreateGroup()?
- How can I detect a destroyed group?

I'm trying to use some dynamically groups but those questions come to my mind.

Really thanks to anyone that awnser! \o/
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
1) I dont really know what DestroyGroup() does, but i used it once on a global variable, and i dont know, but i think it destroyed the whole variable so i couldnt use it anymore,,
2) GroupClear has a GUI action also, it removes all the units from a group, that's all,,
3) idk,, srry (Im not that smart:grin:)
4) Again, idk,, srry :grin:

Through i only answered 1 question fully, i hope it has been helpfull :grin:
 
Level 7
Joined
Jul 20, 2008
Messages
377
GroupClear(): Removes all units from the group but still preserving the group as an in-game object.

DestroyGroup(): Does what it sounds like it does - destroys the group. The memory that the group was taking up will be freed up once you use this.

Yes, you will have to invoke CreateGroup() again after destroying a group. As for detecting a destroyed group, I don't think there's a good way to without nulling the variable after destroying a group, because then you can check if the variable is null.
 
Level 12
Joined
Mar 23, 2008
Messages
942
GroupClear(): Removes all units from the group but still preserving the group as an in-game object.

DestroyGroup(): Does what it sounds like it does - destroys the group. The memory that the group was taking up will be freed up once you use this.

Yes, you will have to invoke CreateGroup() again after destroying a group. As for detecting a destroyed group, I don't think there's a good way to without nulling the variable after destroying a group, because then you can check if the variable is null.
Aren't destroyed groups automatically nulled?
 
Level 7
Joined
Jul 20, 2008
Messages
377
Groups are handles, so no, they are not automatically nulled. Just like how removing a location, removing an unit, and so on forth will not null the variable.
 
Level 12
Joined
Mar 23, 2008
Messages
942
Groups are handles, so no, they are not automatically nulled. Just like how removing a location, removing an unit, and so on forth will not null the variable.

Uhm, for me its easy to set it null since I'm using a function to destroy it.
So, setting it to null after destroyed should get me able to detect it?
It will use memory after setting to null?

Edit: I'm nulling it and its working, but I don't know if it use memory.

Also, sry if I don't give you rep, I already gave to you in another topic.
 
Level 7
Joined
Jul 20, 2008
Messages
377
When you call DestroyGroup(), you free up the memory used by the group. However, the pointer is not null. It's a dangling (wild) pointer. Just like in C++, when you call "delete" on a pointer, the data which the pointer pointed to is now free, but the pointer is still pointing to that spot in memory.

But you don't know what is in that spot in memory because something else might have been assigned to that spot in memory. That's why, in C++, for safety's sake, you null pointers. JASS was written in C++, so JASS follows similar rules.

JASS is kind of stupid though, because it allows handle index leaks (the memory may be free, but since the pointer is not null, it will act as though that place in memory is still taken up). That's why you null locals, because you will not have access to locals after the function ends (and so no way to reference that memory address). Globals, on the other hand, are always there, which is why nulling globals is not necessary.

TLDR: DestroyGroup() is what clears up the memory, but nulling allows that place in memory to be reused. Yes, setting a group variable to null after destroying it will allow you to detect if that group was destroyed (detected implicitly).
 
Status
Not open for further replies.
Top