Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,226
Hello. I am currently creating a rebirth system. It's supposed to create a unit when a unit dies, and if this new unit is still alive after X seconds the old unit is respawned.
However, my struct fails to deallocate somehow. The message "sss" is displayed but shit keeps updating.
However, my struct fails to deallocate somehow. The message "sss" is displayed but shit keeps updating.
JASS:
struct List
integer size = 0
integer array data [99]
public static method create takes nothing returns List
local thistype this = thistype.allocate()
return this
endmethod
public method Add takes integer i returns nothing
set data[size] = i
set size = size + 1
endmethod
public method Remove takes integer id returns nothing
local integer i = 0
local integer j = 0
loop
exitwhen i >= size
if data[i] == id then
loop
exitwhen j >= size
set data[j] = data[j + 1]
set j = j + 1
endloop
set size = size - 1
set i = size + 1
endif
set i = i + 1
endloop
endmethod
endstruct
JASS:
globals
List instances
integer debugCounter = 0
endglobals
struct Rebirth
static constant integer DUMMY_TYPE = 'h000'
static constant real DUMMY_DURATION = 5
integer u
unit deadUnit
location l
real counter
unit egg
static method onInit takes nothing returns nothing
set instances = List.create()
endmethod
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
set this.u = GetUnitTypeId(u)
set this.counter = 0
set this.deadUnit = u
set this.l = GetUnitLoc(u)
set this.egg = CreateUnitAtLoc(GetOwningPlayer(u), DUMMY_TYPE, this.l, 0)
call instances.Add(this)
return this
endmethod
method destroy takes nothing returns nothing
set this.u = 0
call RemoveLocation(this.l)
call instances.Remove(this)
call this.deallocate()
call deallocate(this)
call BJDebugMsg("sss")
endmethod
method Update takes nothing returns nothing
set debugCounter = debugCounter + 1
call BJDebugMsg("Instance: " + I2S(this) + " is being updated!" + " " + I2S(debugCounter) + " " + R2S(this.counter))
set this.counter = this.counter + 0.03
if this.counter > DUMMY_DURATION then
call KillUnit(this.egg)
if IsUnitIdType(this.u, UNIT_TYPE_HERO) == false then
call CreateUnitAtLoc(Player(0), this.u, this.l, 0)
call this.destroy()
call BJDebugMsg("finish1")
else
call ReviveHeroLoc(this.deadUnit, this.l, false)
call this.destroy()
call BJDebugMsg("finish2")
endif
endif
endmethod
endstruct
-
update
-
Events
-
Time - Every 0.03 seconds of game time
-
-
Conditions
-
Actions
-
Custom script: local integer i = instances.size
-
Custom script: loop
-
Custom script: exitwhen i == 0
-
Custom script: call Rebirth( instances.data[i]).Update()
-
Custom script: set i = i - 1
-
Custom script: endloop
-
-