Carl-Fredrik
New Member
- Reaction score
- 51
Hi everyone...
So, earlier I've been doing GUI, and what I learned is "To prevent memory leaks you must destroy groups, locations, forces, etc.".
But now when I'm learning vJASS/JASS I notice that when I destroy global groups (created between "globals" and "endglobals") triggers will fuck up. So I was wondering, won't they leak if I let them exist through the game?
That's basically what I learned in GUI, if you create a variable you'll have to destroy it...
Example (GUI):
Here I set/destroy the group twice and it works perfectly.
Example (JASS/vJASS):
If I destroy the group here this will only work once...
I was also wondering, does all local variables that I create need to be nulled?
Thanks in advance!
// Carl-Fredrik
So, earlier I've been doing GUI, and what I learned is "To prevent memory leaks you must destroy groups, locations, forces, etc.".
But now when I'm learning vJASS/JASS I notice that when I destroy global groups (created between "globals" and "endglobals") triggers will fuck up. So I was wondering, won't they leak if I let them exist through the game?
That's basically what I learned in GUI, if you create a variable you'll have to destroy it...
Example (GUI):
Trigger:
- Bandit Camp
- Events
- Unit - A unit Is attacked
- Conditions
- Or - Any (Conditions) are true
- Conditions
- (Attacked unit) Equal to Assassin 0239 <gen>
- (Attacked unit) Equal to Assassin 0238 <gen>
- (Attacked unit) Equal to Bandit Lord 0253 <gen>
- (Attacked unit) Equal to Tent 0229 <gen>
- (Attacked unit) Equal to Rogue 0236 <gen>
- (Attacked unit) Equal to Bandit 0235 <gen>
- (Attacked unit) Equal to Bandit 0234 <gen>
- (Attacked unit) Equal to Bandit 0237 <gen>
- Conditions
- Or - Any (Conditions) are true
- Actions
- Set Temp_UnitGroup = (Units in Bandits <gen> owned by Neutral Passive)
- Unit Group - Pick every unit in Temp_UnitGroup and do (Unit - Change ownership of (Picked unit) to Neutral Hostile and Change color)
- Custom script: call DestroyGroup (udg_Temp_UnitGroup)
- Set Temp_UnitGroup = (Units in Bandits <gen> owned by Neutral Hostile)
- Unit Group - Order Temp_UnitGroup to Attack (Attacking unit)
- Custom script: call DestroyGroup (udg_Temp_UnitGroup)
- Events
Here I set/destroy the group twice and it works perfectly.
Example (JASS/vJASS):
JASS:
scope MSCommand initializer InitMS
globals
private group MSGROUP = CreateGroup()
endglobals
private function TypeComparisons takes nothing returns boolean
local unit u = GetFilterUnit()
return IsUnitType(u, UNIT_TYPE_HERO) == true and IsUnitAliveBJ(u) == true and GetOwningPlayer(u) == GetTriggerPlayer()
endfunction
private function DoThis takes nothing returns nothing
call DisplayTextToForce( GetForceOfPlayer(GetTriggerPlayer()), ( "|c00ff8000Movement Speed: " + ( R2S(GetUnitMoveSpeed(GetEnumUnit())) + udg_Endtag ) ) )
endfunction
private function Actions takes nothing returns nothing
call GroupEnumUnitsInRect(MSGROUP, GetPlayableMapRect(), Condition (function TypeComparisons))
call ForGroup(MSGROUP, function DoThis)
call GroupClear(MSGROUP)
call AdjustPlayerStateBJ(-500, GetTriggerPlayer(), PLAYER_STATE_RESOURCE_GOLD)
endfunction
private function InitMS takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerChatEvent(t, Player(0), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(1), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(2), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(3), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(4), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(5), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(6), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(7), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(8), "-ms", true)
call TriggerRegisterPlayerChatEvent(t, Player(9), "-ms", true)
call TriggerAddAction(t, function Actions)
endfunction
endscope
If I destroy the group here this will only work once...
I was also wondering, does all local variables that I create need to be nulled?
Thanks in advance!
// Carl-Fredrik