
-----------------------------------
mike200015
Sat Mar 12, 2005 11:01 pm

If Help!
-----------------------------------
In my game i have : 
get answer

and answer is an int, and if the user enters something other than an int, it messes up the program, and gives me an error, since its the wrong type, so i want to make it error proof, and keep asking the question, and then if what the user types in is any int, then it will continue the game. 
So how would i make the program check if the input is any int :?:

-----------------------------------
Bacchus
Sat Mar 12, 2005 11:42 pm


-----------------------------------
strintok()
strint()
F10

there may also be a tutorial on error proofing

-----------------------------------
mike200015
Sat Mar 12, 2005 11:44 pm


-----------------------------------
im not trying to switch from a string to an int or anything.. i jus want to chek if the input was any int number.. and if it was.. then continue on

-----------------------------------
Bacchus
Sat Mar 12, 2005 11:49 pm


-----------------------------------
var errorproof:string
var num:int
loop
   cls
   put "Please enter an Integer"
   get errorproof
   if strintok(errorproof) then
      num:=strint(errorproof)
      exit
   end if
   put "That is not an Integer!"
   delay(500)
end loop
put "That IS an Integer!"

-----------------------------------
mike200015
Sat Mar 12, 2005 11:59 pm


-----------------------------------
ooo.. ok i get it now.. yea it works great.. thanx!  :D

-----------------------------------
mike200015
Sun Mar 13, 2005 12:03 am


-----------------------------------
Another thing i want to error proof is.. i ask the user to enter their name.. and i want to make it loop the question if they enter more than 15 characters.. so how would i make a loop for that.. and it exits when the user inputs 15 characters or less?

-----------------------------------
Flikerator
Sun Mar 13, 2005 12:12 am


-----------------------------------
Another thing i want to error proof is.. i ask the user to enter their name.. and i want to make it loop the question if they enter more than 15 characters.. so how would i make a loop for that.. and it exits when the user inputs 15 characters or less?

var name : string
loop
    put "Enter a name (Less then or equal to 15 chars)"
    get name
    if length (name) >= 16 then
        put "I sad less then or eqaul to 15!"
        delay (500)
        cls
    else
        exit when name = name
    end if
end loop
put "Your name is ", name

-----------------------------------
mike200015
Sun Mar 13, 2005 12:35 am


-----------------------------------
hey .. thnx Flickerator.. worked great! :D

-----------------------------------
Cervantes
Sun Mar 13, 2005 9:04 am


-----------------------------------
Flik: you don't need that exit when name = name part.  Simply typing exit is good enough.
Also, it would be a good idea to use get : *.  Try running flik's code, and inputing "ABCDEFG HIJKLMNO".  That string is >= 16, but it tells you you're name is ABCDEFG because get stops at spaces.  get : * only stops at enter, however, so it will take the whole line of input into the variable.
Also, if you don't have get : *, it can mess up the next get in your program.  Without the : *, try inputting "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".  All the A's before the space will be put into the name variable.  Name is greater than 16, so it tells you that it is and restarts the loop.  Then it trys to get input again, but there's still stuff in the keyboard buffer.  So it takes that stuff, and then puts it into name.  name is once again greater than 16, so it tells you so, AGAIN!
Cheers,
-Cervantes

-----------------------------------
Flikerator
Sun Mar 13, 2005 11:26 am


-----------------------------------
Flik: you don't need that exit when name = name part.  Simply typing exit is good enough.
Also, it would be a good idea to use get : *.  Try running flik's code, and inputing "ABCDEFG HIJKLMNO".  That string is >= 16, but it tells you you're name is ABCDEFG because get stops at spaces.  get : * only stops at enter, however, so it will take the whole line of input into the variable.
Also, if you don't have get : *, it can mess up the next get in your program.  Without the : *, try inputting "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".  All the A's before the space will be put into the name variable.  Name is greater than 16, so it tells you that it is and restarts the loop.  Then it trys to get input again, but there's still stuff in the keyboard buffer.  So it takes that stuff, and then puts it into name.  name is once again greater than 16, so it tells you so, AGAIN!
Cheers,
-Cervantes

Wow I didn't know about thatr keyboard buffer part, good to know. I also didn't know about just exit so thanks ^^;

-----------------------------------
mike200015
Mon Mar 14, 2005 3:00 pm


-----------------------------------
yea i used the :* after the get.. helps also wit the error proofing.  Thanx :)
