Jump to content


Photo

divisions by 0


  • Please log in to reply
4 replies to this topic

#1 12warr12

12warr12

    GMC Member

  • GMC Member
  • 688 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
Posted ImageRate this topic:0 | 1 | 2 | 3 | 4 | 5

#3 PetzI

PetzI

    GMC Member

  • GMC Member
  • 1094 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
Posted Image I did not make this game.

Let me know if you're a fan of Makermod or Lugormod!

#4 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 11111 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
"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis

#5 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 23559 posts
  • Version:GM:Studio

Posted 09 May 2012 - 11:40 PM

You can also use the max function...

exp /= max(1, val);

  • 0

Button_DynamicPuddles_zps068ef8eb.png Button_Flappy_zps7fcff3b6.png Button_RogueLike_zps6f3451a3.png IKrQvWr.png Button_MyGames_zpse9e80bb0.png





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users