Then that sounds worse than I thought, because for me (in single player) the elapsed time being 0.50 or higher makes those conditions work as intended, whereas, for you, the event should have its value set to 1.00 or higher.
I tried to type cast reals into integer using this simple function:
JASS:
function r2i takes real r returns integer
return r
endfunction
// which is not the same as the native R2I
and I have done another test where I use that 'r2i' custom function, trying to see the timer's real value when the game elapsed time is 0.10 and 0.50.
0.10:
-
Initialization
-
Events
-
Time - Elapsed game time is 0.10 seconds
-
Conditions
-
Actions
-
Countdown Timer - Start timer as a One-shot timer that will expire in 1.00 seconds
-
Countdown Timer - Pause timer
0.50:
-
Initialization
-
Events
-
Time - Elapsed game time is 0.50 seconds
-
Conditions
-
Actions
-
Countdown Timer - Start timer as a One-shot timer that will expire in 1.00 seconds
-
Countdown Timer - Pause timer
Display timer info:
JASS:
function r2i takes real r returns integer
return r
endfunction
function ShowValues takes nothing returns nothing
call ClearTextMessages()
call BJDebugMsg("|cffffcc00Blizzard's type casting (R2I)|r")
call BJDebugMsg("Remaining: "+I2S(R2I(TimerGetRemaining(udg_timer))))
call BJDebugMsg("Timeout: "+I2S(R2I(TimerGetTimeout(udg_timer))))
call BJDebugMsg("Elapsed: "+I2S(R2I(TimerGetElapsed(udg_timer))))
call BJDebugMsg("|cffffcc00Custom function (r2i)|r")
call BJDebugMsg("Remaining: "+I2S(r2i(TimerGetRemaining(udg_timer))))
call BJDebugMsg("Timeout: "+I2S(r2i(TimerGetTimeout(udg_timer))))
call BJDebugMsg("Elapsed: "+I2S(r2i(TimerGetElapsed(udg_timer))))
call BJDebugMsg(" ")
endfunction
//===========================================================================
function InitTrig_ESC takes nothing returns nothing
set gg_trg_ESC = CreateTrigger( )
call TriggerRegisterPlayerEvent(gg_trg_ESC, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(gg_trg_ESC, function ShowValues)
endfunction
Screenshots:
0.10:
0.50:
As DSG said, they are not safe to be compared like that. I'd still use typecasting instead.
Also, while I was testing this, I tried to change the elapsed game time to
0.25, and it returned the same results as the
0.50's, which means that my claim about having an elapsed game time higher than X value is wrong and not safe at all. You'd be better off typecasting when comparing real data types. If you're worried about rounding values, try to use this:
JASS:
function RoundUp takes real r returns integer
return R2I(r + .5)
endfunction
// or
function RoundDown takes real r returns integer
return R2I(r - .5)
endfunction
Example:
-
Initialization
-
Events
-
Time - Elapsed game time is 0.10 seconds
-
Conditions
-
Actions
-
Countdown Timer - Start timer as a One-shot timer that will expire in 1.00 seconds
-
Countdown Timer - Pause timer
JASS:
function ShowValues takes nothing returns nothing
call ClearTextMessages()
call BJDebugMsg("|cffffcc00Blizzard's typcasting (|rR2I|cffffcc00)|r")
call BJDebugMsg("Remaining: "+I2S(R2I(TimerGetRemaining(udg_timer))))
call BJDebugMsg("Timeout: "+I2S(R2I(TimerGetTimeout(udg_timer))))
call BJDebugMsg("Elapsed: "+I2S(R2I(TimerGetElapsed(udg_timer))))
call BJDebugMsg("|cffffcc00Custom function (|rRoundUp|cffffcc00)|r")
call BJDebugMsg("Remaining: "+I2S(RoundUp(TimerGetRemaining(udg_timer))))
call BJDebugMsg("Timeout: "+I2S(RoundUp(TimerGetTimeout(udg_timer))))
call BJDebugMsg("Elapsed: "+I2S(RoundUp(TimerGetElapsed(udg_timer))))
call BJDebugMsg(" ")
endfunction
//===========================================================================
function InitTrig_ESC takes nothing returns nothing
set gg_trg_ESC = CreateTrigger( )
call TriggerRegisterPlayerEvent(gg_trg_ESC, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(gg_trg_ESC, function ShowValues)
endfunction