Users browsing this thread: 2 Guest(s)
Game Maker help
#1
Hey everyone. I'm having trouble coding something, figured I could get some help

basically it's an app that tests if the number I inserted is even or odd. The coding in GML goes as follows:

Code:
var number = get_integer("Type a Number.",0);  
if( is_real(number)== true){
     if(number%2 ==0){
     show_message("The number "+string(number)+" is even.");
     }
      else if(number%2==1){
      show_message("The number "+string(number)+" is odd.");
      }
}
else{
show_message("Insert numbers only.");
}
The app gets the number and divides it by two. If there are no remainders, it is even; and if there is a remainder, it is odd.
the exact problem i'm having is that currently, I am able to type a word and since GML considers words as "0", the app gives out the even message when it is clearly not even (it's not even a number!!)

If there was a way to limit the input somehow I'd be very grateful.
Spriter Gors】【Bandcamp】【Twitter】【YouTube】【Tumblr】【Portifolio
If you like my C+C, please rate me up. It helps me know I'm helping!
[Image: deT1vCJ.png]
Reply
Thanked by:
#2
Googling a little points me to

string_digits(number) strips all letters out

for the sake of testing, have it print out what string_digits(number) returns, if it's completely empty or a 0, if it's completely empty just slap another if in

too lazy to write gamemaker but basically the code after that would look like
>please give numbers (code to get numbers)
>(if using string_digits(number)) hey this isn't a number shithead
>(if it passes, if for even and odd and all that)
Reply
Thanked by: puggsoy


Forum Jump: