HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

When is 0.00 > 0.00?

07-29-2007, 12:21 AM#1
Pyrogasm
I'm trying to avoid creating/destroying new timers every time this function runs, so I'm just pausing it, telling it to run a null function on a 0.00 second callback, and then pausing it again in order to clear the time remaining.

However, this function will display the remaining time as 0.00 but still display the "Un-Slept" message... Why? Is it because of Wc3's floating point and the time remaining is really something like 0.000001?

Collapse JASS:
function CSF_UnSlept takes nothing returns boolean
    local unit U = GetTriggerUnit()
    local string UTable = GetAttachmentTable(U)
    local timer T = GetTableTimer(UTable, "CSF Unit Timer")

    call BJDebugMsg(R2S(TimerGetRemaining(T)))
    if TimerGetRemaining(T) > 0.00 and GetUnitTypeId(GetEventDamageSource()) != CSF_DummyUnitId() then
        call SetTableBoolean(UTable, "CSF Short Duration", false)
        call PauseTimer(T)
        call TimerStart(T, 0.00, false, null)
        call PauseTimer(T)
        call BJDebugMsg("Un-slept")
        call ExecuteFunc("CSF_UnSleptExecute")
    endif

    set U = null
    set T = null
    return false
endfunction
07-29-2007, 12:31 AM#2
TheSecretArts
try display time remaining or maybe the timer has to run if its called.
07-29-2007, 12:32 AM#3
Pyrogasm
Quote:
Originally Posted by TheSecretarts
try display time remaining or maybe the timer has to run if its called.
Quote:
Originally Posted by Me
call BJDebugMsg(R2S(TimerGetRemaining(T)))
07-29-2007, 12:39 AM#4
TheSecretArts
i think that the timer has to run once and thus time remaining is forced over 0
07-29-2007, 01:57 AM#5
Pyrogasm
Woah. Weird, funky bug! If you pause the timer before calling a TimerStart(), it keeps its previous elapsed time even after it expires on the new function. If you do not pause it, the new elapsed time becomes 0.

Collapse JASS:
function CSF_UnsleepDummyFunc takes nothing returns nothing
    call BJDebugMsg("Expired")
    call PauseTimer(GetExpiredTimer())
endfunction

function CSF_UnSleptExecute takes nothing returns nothing
    call BJDebugMsg("Attacker: "+GetUnitName(GetEventDamageSource())+"; Damage: "+R2S(GetEventDamage()))
endfunction

function CSF_UnSlept takes nothing returns boolean
    local unit U = GetTriggerUnit()
    local string UTable = GetAttachmentTable(U)
    local timer T = GetTableTimer(UTable, "CSF Unit Timer")

    call BJDebugMsg(R2S(TimerGetRemaining(T)))
    if TimerGetRemaining(T) > 0.00 and GetUnitTypeId(GetEventDamageSource()) != CSF_DummyUnitId() then
        call SetTableBoolean(UTable, "CSF Short Duration", false)
//        call PauseTimer(T)
        call TimerStart(T, 0.01, false, function CSF_UnsleepDummyFunc)
        call BJDebugMsg("Un-slept")
        call ExecuteFunc("CSF_UnSleptExecute")
    endif

    set U = null
    set T = null
    return false
endfunction
Either way, the message "Expired" shows up, but the elapsed time is different depending on if you pause it or not before calling the TimerStart().
07-29-2007, 02:22 AM#6
DioD
this is soo damn easy... call timer 0.00 store timer remaining and declare it as ZERO

Quote:
call TimerStart(T, 0.00, false, null)
...
set Ex_ZERO_OF_TIMER = TimerGetRemaining(T)

after it

if TimerGetRemaining(T) > 0.00 Ex_ZERO_OF_TIMER
07-29-2007, 02:47 AM#7
Pyrogasm
I really don't understand what you're saying.