
-----------------------------------
nin
Thu Jan 18, 2007 8:31 pm

errortrap
-----------------------------------
how do u errortrap words? 
what i mean is that in my game , for the answerable questions, the user can type anything they want but i only want them to type numbers and not words.
And if they type words, it should errortrap it.
so how can i do that?

-----------------------------------
ericfourfour
Thu Jan 18, 2007 9:51 pm

RE:errortrap
-----------------------------------
I believe strintok and strrealok will suit you perfectly.

-----------------------------------
nin
Thu Jan 18, 2007 9:59 pm

Re: errortrap
-----------------------------------
wats that?

-----------------------------------
Expirant
Thu Jan 18, 2007 10:25 pm

Re: errortrap
-----------------------------------
Press F10 while in Turing.

But basically strintok (x:string) is a function that returns whether 'x' is in the correct format for an integer type, and strreal does the same thing but for real numbers.

Ex:


var s : string := "Hello"
var n : string := "5"
var r : string := "5.55"

put strintok (s)
put strrealok (s)
put strintok (n)
put strrealok (r)


So to check if an answer to a question is in the correct format (a.k.a an integer) use:


var answer : string

put "What is 5 + 5?"
get answer : * % Numbers are < one word, but the  : * will keep the user from skipping lines

if strintok (answer) and strint (answer) = 10 then
    put "Correct!"
end if


Hope that clears it up,
Expirant

-----------------------------------
nin
Thu Jan 18, 2007 11:22 pm

Re: errortrap
-----------------------------------
n if u were keppomg trck of the score how would u do that?

-----------------------------------
Expirant
Fri Jan 19, 2007 10:54 am

Re: errortrap
-----------------------------------
Well, think about it.  When does their score increase? When they get an answer correct, right? So...where in your code does it check if the answer is correct?
So if they get the answer correct, increase the score by 1. At that point in your code, you would have score += 1 (or score := score + 1). In the code I wrote, it would be:


var answer : string
var score := 0 

put "What is 5 + 5?" 
get answer : *

if strintok (answer) and strint (answer) = 10 then 
    put "Correct!" 
    score += 1
end if

put "Final score: ", score


...

Think about it for a while, and if you're still having trouble, ask again.
