1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Trigger] Question about groups

Discussion in 'Triggers & Scripts' started by Saishy, Feb 3, 2009.

  1. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    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/
     
  2. Yixx

    Yixx

    Joined:
    Oct 12, 2008
    Messages:
    1,492
    Resources:
    3
    Spells:
    3
    Resources:
    3
    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:
     
  3. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    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.
     
  4. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Aren't destroyed groups automatically nulled?
     
  5. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    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.
     
  6. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    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.
     
  7. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    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).
     
  8. Saishy

    Saishy

    Joined:
    Mar 23, 2008
    Messages:
    947
    Resources:
    0
    Resources:
    0
    Really thanks!

    (Can't give you more rep xD)