Jump to content


divisions by 0

  • Please log in to reply
4 replies to this topic

#1 12warr12


    GMC Member

  • GMC Member
  • 696 posts
  • Version:Unknown

Posted 09 May 2012 - 06:47 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



  • GMC Member
  • 866 posts
  • Version:GM8

Posted 09 May 2012 - 06:53 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


    GMC Member

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

Posted 09 May 2012 - 07:52 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


    GMC Member

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

Posted 09 May 2012 - 11:28 PM

if variable==0 variable=1


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

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong


"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis


"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 Games

  • Administrators
  • 25708 posts
  • Version:GM:Studio

Posted 09 May 2012 - 11:54 PM

You can also use the max function...

exp /= max(1, val);

  • 0