- Joined
- Jul 20, 2009
- Messages
- 835
I will just post that out here. That's kinda strange about JASS.
I was coding Ghoul boss for TKoK. And I've loled along with IyD (TGM Team's algorithmizator and balancer) from these things.
To start off, here is the code:
The code is pretty simple and must work, huh? But no! This condition:
It was confirmed with the debug:
Along every other variants, it shown me
That was just for you to think that over and not getting caught by this bug.
I was coding Ghoul boss for TKoK. And I've loled along with IyD (TGM Team's algorithmizator and balancer) from these things.
To start off, here is the code:
JASS:
private function P1_TimerCallback takes nothing returns nothing
set P1_TimeRemaining = P1_TimeRemaining - .04
set P1_TimePassed = P1_TimePassed + .04
if I2R(R2I(P1_TimePassed/P1_MiniSpawnRateBuff)) == P1_TimePassed/P1_MiniSpawnRateBuff then
if P1_MiniSpawnRate > 1 then
set P1_MiniSpawnRate = P1_MiniSpawnRate - 1
call DisplayTimedTextToPlayer(GetLocalPlayer(),0 , 0, 6, UNIT_MESSAGE_FONT_COLOR+"Ghoul:|r Come to the lunch!")
endif
call UnitAddBuff(Ghoul,Ghoul,BUFF_TYPE_FEAST,BUFF_PERMANENT)
endif
if P1_TimeRemaining <= 0 then
set P1_TimeRemaining = 0
call PauseTimer(P1_Timer)
// Also delete all minis!
call CleanUpBossUnits(P1_MinisGroup)
// Phase 2 begins here.
if not isDefeated then
set Phase = 2
call P2_Execute.execute()
endif
endif
endfunction
The code is pretty simple and must work, huh? But no! This condition:
I2R(R2I(P1_TimePassed/P1_MiniSpawnRateBuff)) == P1_TimePassed/P1_MiniSpawnRateBuff
never fires. I was surprised actually, I always thought that R2I
works as trunc function in different programming languages. What Trunc actually does? It converts real to integer by truncating every number after floating point. But R2I
just rounds the number down. It's okay with me, it must work well then. But the rounding down there is something weird. For example, R2I(1.000)
will return 0.000. Lol what?It was confirmed with the debug:
call BJDebugMsg(R2S(I2R(R2I(P1_TimePassed/P1_MiniSpawnRateBuff)))+ " == " + R2S(P1_TimePassed/P1_MiniSpawnRateBuff))
Along every other variants, it shown me
0.000 == 1.000
. And this one is wrong because rounding down is nothing good like that. It rounded 1.000 down to 0.000, but it must stay 1.000 because 1 > 0.That was just for you to think that over and not getting caught by this bug.