Division by zero error

Started by DR119, December 21, 2017, 09:55:03 PM

Previous topic - Next topic

DR119

I want Mugen to return the amount of centiseconds the fight lasted for. I already created explods for the minutes, seconds and deciseconds. I did this by setting a variable timer for roundstate=2 and then divide this value by tickspersecond to detect the seconds. Basically, all values are calculated with the same formula and everything (except for the centiseconds) works fine. If I try to calculate those, an error message shows up in the mugen console, which states that it's a division by zero. But neither the var nor tickspersecond equals 0... So why does this error message appear?
Here's my code:

[state -2];returns time: adds 1 every frame if roundstate = 2
type = varadd
trigger1 = roundstate = 2
var(2) = 1

[state -2];centiseconds (does not work)
type = explod
trigger1 = win
anim = f400 + floor(var(2) / (tickspersecond / 100) ) % 10
id = 400
pos = 100, 141.25
space = screen
ontop = 1

[state -2];deciseconds (works)
type = explod
trigger1 = win
anim = f400 + floor(var(2) / (tickspersecond / 10) ) % 10
id = 401
pos = 70, 141.25
space = screen
ontop = 1

[state -2];seconds (works)
type = explod
trigger1 = win
anim = f400 + floor(var(2) / tickspersecond) % 10
id = 402
pos = 40, 141.25
space = screen
ontop = 1

[state -2];10 seconds (works)
type = explod
trigger1 = win
anim = f400 + floor(var(2) / tickspersecond / 10) % 6
id = 403
pos = 10, 141.25
space = screen
ontop = 1

[state -2];minutes (works)
type = explod
trigger1 = win
anim = f400 + floor(var(2) / tickspersecond / 60) % 10
id = 404
pos = -20, 141.25
space = screen
ontop = 1

Jesuszilla

TicksPerSecond returns an integer. When you divide it by 100, you're doing integer division. Change the 100 to 100.0 and change 10 to 10.0 and 60 to 60.0 to get the division you're expecting.