- Joined
- May 12, 2018
- Messages
- 145
My purpose is to spawn ELEMENTUNIT immediately when structures called FORGESITEs are pre-placed on map or when I build them.
And, ELEMENTUNIT must also die together when FORGESITE dies.
The following is a script written for the test.
The DeathEvent part is currently not working for my purpose. Creating ELEMENTUNIT for each FORGESITE does not seem to make a problem (so far), but, When FORGESITE dies, ELEMENTUNIT does not die at the same time.
I would appreciate it more if you could provide me with checking a memory leak problem or solutions to it too.
And, ELEMENTUNIT must also die together when FORGESITE dies.
The following is a script written for the test.
JASS:
scope ForgeSiteDevastator initializer init
globals
private constant integer ELEMENTUNIT = 'n033'
private constant integer FORGESITE = 'o013'
private constant real HEIGHT = 140
private constant real RATED = 100
private constant real FACING = 315
endglobals
private struct Data
integer id
unit source
unit element
method destroy takes nothing returns nothing
call deallocate()
call KillUnit(element)
set source = null
set element = null
endmethod
static method create takes unit du returns Data
local Data D = Data.allocate()
set D.source = du
set D.element = CreateUnit(GetOwningPlayer(D.source), ELEMENTUNIT, GetUnitX(D.source), GetUnitY(D.source), FACING)
return D
endmethod
endstruct
private function Action1 takes nothing returns nothing
local unit forge = udg_UDexUnits[udg_UDex]
local Data D = GetUnitUserData(forge)
call D.destroy()
endfunction
private function Condition0 takes nothing returns boolean
return udg_UnitTypeOf[udg_UDex] == FORGESITE
endfunction
private function Action0 takes nothing returns nothing
local unit forge = udg_UDexUnits[udg_UDex]
local Data D = Data.create(forge)
set forge = null
endfunction
private function init takes nothing returns nothing
local trigger t0 = CreateTrigger()
local trigger t1 = CreateTrigger()
call TriggerRegisterVariableEvent( t0, "udg_UnitIndexEvent", EQUAL, 1.00 )
call TriggerAddCondition(t0, Condition(function Condition0) )
call TriggerAddAction( t0, function Action0 )
call TriggerRegisterVariableEvent( t1, "udg_DeathEvent", EQUAL, 1.00 )
call TriggerAddCondition( t1, Condition(function Condition0) )
call TriggerAddAction( t1, function Action1 )
set t0 = null
set t1 = null
endfunction
endscope
[CODE=JASS]
The DeathEvent part is currently not working for my purpose. Creating ELEMENTUNIT for each FORGESITE does not seem to make a problem (so far), but, When FORGESITE dies, ELEMENTUNIT does not die at the same time.
I would appreciate it more if you could provide me with checking a memory leak problem or solutions to it too.
Last edited: