Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Is there a way for only numbers to be entered?
- ShadowWren
-
Scratcher
7 posts
Is there a way for only numbers to be entered?
I'm making a times table game for school, and I was wondering if when the user puts in an answer to a question, can it recognize if the answer is a number, and not a letter. So far, I've made it so it recognizes if the answer is correct (Or incorrect).
Any help is appreciated.
Any help is appreciated.
- drmcw
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
Last edited by drmcw (June 30, 2016 05:34:30)
- asivi
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
if <((answer) mod (answer)) = [0]> then
..I's a number...::grey
end
- deck26
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
Fails for zero though.if <((answer) mod (answer)) = [0]> then
..I's a number...::grey
end
- asivi
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
Fails for zero though.if <((answer) mod (answer)) = [0]> then
..I's a number...::grey
end
if <<((answer) mod (answer)) = [0]> or < (answer) = [0]>>then
..I's a number...::grey
end
- deck26
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
You could also create an on-screen keypad so your input is coming from there rather than an ask block.
Not too difficult, when the sprite is clicked compare the mouse x and y with the x and y position of the sprite to work out which ‘key’ is pressed. Or use separate sprites but I prefer the single sprite method.
Not too difficult, when the sprite is clicked compare the mouse x and y with the x and y position of the sprite to work out which ‘key’ is pressed. Or use separate sprites but I prefer the single sprite method.
- ShadowWren
-
Scratcher
7 posts
Is there a way for only numbers to be entered?
Thanks heaps for all the suggestions!
- deck26
-
Scratcher
1000+ posts
Is there a way for only numbers to be entered?
In case it helps, here's a numeric keypad https://scratch.mit.edu/projects/115261213/
- yclee0206
-
Scratcher
100+ posts
Is there a way for only numbers to be entered?
What about this? I used this somewhere in my projects.
If answer is not a number, answer*1 will return as zero, and that is not equal to answer.
If ((answer) =((answer) *[1]))
It's a number
End
If answer is not a number, answer*1 will return as zero, and that is not equal to answer.
Last edited by yclee0206 (June 30, 2016 12:05:42)
- Discussion Forums
- » Help with Scripts
-
» Is there a way for only numbers to be entered?