is there any way of ignoring the string divisions by zero?
On my exp gain calculating, I have many variables that add numbers to the exp, and the overall of those vars, will be divided by another variable, wich sometimes can be 0, when its 0, an error comes up... how to fix this without having to make if var...=0{}else {}...?
divisions by 0
Started by 12warr12, May 09 2012 06:33 PM
4 replies to this topic
#1
Posted 09 May 2012 - 06:33 PM
#2
Posted 09 May 2012 - 06:39 PM
make it to one!
it will be the same number!
2 will increase it 1 will make it the same!
it will be the same number!
2 will increase it 1 will make it the same!
#3
Posted 09 May 2012 - 07:38 PM
You have to be a bit more specific. Are there ever any negative numbers and what do you want it to return when a division by 0 occurs?
#4
Posted 09 May 2012 - 11:14 PM
if variable==0 variable=1
Period.
But if that variable is going to equal 0, you obviously messed up somewhere down the line or didn't think it all the way through. The only time I've ever had to use that conditional was when programming objects that require Instance Creation Code to function properly and I felt like being too lazy to actually include an ICC for each instance of that object in the game.
Period.
But if that variable is going to equal 0, you obviously messed up somewhere down the line or didn't think it all the way through. The only time I've ever had to use that conditional was when programming objects that require Instance Creation Code to function properly and I felt like being too lazy to actually include an ICC for each instance of that object in the game.
#5
Posted 09 May 2012 - 11:40 PM
You can also use the max function...
exp /= max(1, val);
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











