| 02-24-2005, 08:59 PM | #1 |
This is a slightly advanced question. I'm working with a periodic trigger that deals with Unit Groups. Naturally, I want to do take care to prevent memory leaks. The problem is that once a Unit Group has been destroyed or set to null, it no longer has it's default value. So, a trigger that looks like this: Code:
Awesome Presence
Events
Time - Every 5.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in [color=orange]ug_AwesomePresenceCasters[/color] and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Picked unit) is alive) Equal to True
Then - Actions
Set [color=orange]u_CurrentUnit[/color] = (Picked unit)
Unit Group - Remove all units from [color=orange]ug_StunnedUnitGroup[/color]
Unit Group - Remove all units from [color=orange]ug_AwesomePresenceGroup[/color]
Set SpecialEffectIndex = 0
Unit Group - Add all units of (Units within [color=orange]i_AwesomeRadius[/color] of (Position of [color=orange]u_CurrentUnit[/color]) matching (((Owner of [color=orange]u_CurrentUnit[/color]) is an ally of (Owner of (Matching unit))) Equal to False)) to [color=orange]ug_AwesomePresenceGroup[/color]
[color=green]// Do Some stuff to those units[/color]
Custom script: call DestroyGroup(udg_ug_AwesomePresenceGroup)
Custom script: set udg_ug_AwesomePresenceGroup = null
Else - Actions
[color=green] ... (more code, unimportant for this example)[/color]Will stop working after one iteration. The reason for this is the destruction of the ug_AwesomePresenceGroup Unit Group. I currently have a way around it that I don't like - i can first Set ug_AwesomePresenceGroup to a Unit Group of some kind, and then work with it from there. Is there an easier way around my problem? |
| 02-24-2005, 09:24 PM | #2 |
Guest | You can't use a non-initialized unit group ( i.e. destroyed or null ). If you examine the map scripts you will see every unit group you use has to be initializaed. Use this to do so: set unitgroupvar = CreateGroup() |
| 02-24-2005, 10:18 PM | #3 |
Guest | Create another group variable with no unit in it that you won't use, call it "group_null" for example Set unitgroupvar = group_null should work, as defaults unit group consider 'no units' rather as 'null' |
| 02-25-2005, 02:25 AM | #4 |
Thanks Sabugostorm - that helps immensely! BadFurDay - I don't think that method works, but it might just be my fault. According to the behavior I observed when I tried your solution, I think when you set two objects equal to one another, it considers them exactly the same (from a programming perspective, it points to the same memory location). Thus, when you set the object to null, you can't use your blank unit group anymore. |
