Jump to content


Photo

divisions by 0


  • Please log in to reply
4 replies to this topic

#1 12warr12

12warr12

    GMC Member

  • GMC Member
  • 681 posts
  • Version:Unknown

Posted 09 May 2012 - 06:33 PM

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 {}...?
  • 0

#2 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

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!
  • 0

#3 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1056 posts
  • Version:GM:Studio

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?
  • 0

#4 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 9828 posts
  • Version:GM8

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.
  • 0

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 21290 posts
  • Version:GM:Studio

Posted 09 May 2012 - 11:40 PM

You can also use the max function...

exp /= max(1, val);

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users