HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Trouble with Real equation

10-05-2006, 07:18 AM#1
The_AwaKening
For some reason, this script won't run in the game. I narrowed it down to the loop shown below by using BJDebugMsg. Don't worry about the code making sense. I removed 90% of the code to make it easier to read.

Collapse JASS:
function Trig_Awards_Actions takes nothing returns nothing
 local integer i=0
 local real array r
    loop
        exitwhen i>9
        set r[1] = I2R(udg_infoHKills[i])
        set r[2] = I2R( udg_infoDeaths[i] + udg_infoHKills[i] )
        set r[0] = ( r[1] / r[2] ) * 100.00
        set i=i+1
    endloop
endfunction

Any idea why that would crash the thread?
10-05-2006, 07:55 AM#2
PipeDream
Divide by zero
10-05-2006, 10:30 AM#3
zen87
lol yeah, if a unit have no death and no kills then it will be r[1]/0 = taboo, well if you want to fix it without affecting much of your spells, i suggest :
Collapse JASS:
function Trig_Awards_Actions takes nothing returns nothing
 local integer i=0
 local real array r
    loop
        exitwhen i>9
        set r[1] = I2R(udg_infoHKills[i])
        set r[2] = I2R( udg_infoDeaths[i] + udg_infoHKills[i] )
        set r[0] = ( (r[1]+1) / (r[2]+1) ) * 100.00
        set i=i+1
    endloop
endfunction
again, make sure your r[2] wont reach negative values
10-05-2006, 10:53 AM#4
Fireeye
i personally would make it like:
Collapse JASS:
function Trig_Awards_Actions takes nothing returns nothing
local integer i=0
local real array r
loop
    exitwhen i>9
    set r[1] = I2R(udg_infoHKills[i])
    set r[2] = I2R( udg_infoDeaths[i] + udg_infoHKills[i] )
    if r[2] >= 1.00 then
        set r[0] = ( r[1] / r[2] ) * 100.00
    endif
    set i=i+1
endloop
endfunction
10-05-2006, 02:27 PM#5
The_AwaKening
Thanks guys, didn't realise divide by 0 crashes. + rep