- Joined
- Nov 30, 2007
- Messages
- 1,202
I'm trying to create a timer attached to [Option][PlayerId] and a way to retrieve the time remaining. But I'm not sure if im allocating too much memory for it and how to write the remove statements.
It's entierly possible probably to completely ditch Table cdTable and just use TableArray, but I'm not sure how to write this.
Futhermore, this whole struct is probably redudant too, but since I cant really use TableArray this was the best I could come up with.
Hope it's clear what I'm trying to acomplish from code.
It's entierly possible probably to completely ditch Table cdTable and just use TableArray, but I'm not sure how to write this.
Futhermore, this whole struct is probably redudant too, but since I cant really use TableArray this was the best I could come up with.
Hope it's clear what I'm trying to acomplish from code.
JASS:
struct Cooldown
static TableArray ta
static Table cdTable
private SpellOption option
private integer pid
static method getTime takes SpellOption o, integer pid returns real
local timer t = ta[o].timer[pid]
return TimerGetRemaining(t)
endmethod
static method onFinish takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
local Cooldown cd = cdTable[id]
call ta[option].timer.remove(cd.pid) // <----
call cdTable.remove(id) // <----
call PauseTimer(t)
call DestroyTimer(t)
set t = null
call cd.deallocate()
endmethod
static method create takes integer pid, SpellOption o, integer time returns thistype
local thistype this = .allocate()
local timer t = CreateTimer()
set this.option = o
set this.pid = pid
call TimerStart(t, o.cooldown, false, function thistype.onFinish)
set ta[o].timer[pid] = t
set cdTable[GetHandleId(t)] = this
set t = null
return this
endmethod
private static method onInit takes nothing returns nothing
set ta = TableArray[24] // I got 24 child keys to each option, is this correct then?
set cdTable = Table.create()
endmethod
endstruct
Last edited: