This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-05-19 16:27:57

RAPPERMAN
Scratcher
Registered: 2007-05-19
Posts: 1

VARIABLE INPUTS FROM KEYBOARD

HI

First of all I think what you are doing with Scratch is fantastic.  Both me and my son are having lots of fun with this!

I am trying to write a simple addition and multiplication game where it will display the problem (eg. 6 + 7 = ) and then read a variable for the answer that is TYPED IN from the keyboard.  This variable will then be compared to the correct answer.  My question is:  Is there a way of reading variables from the keyboard?

Offline

 

#2 2007-05-19 19:49:19

PeterB
Scratcher
Registered: 2007-05-18
Posts: 14

Re: VARIABLE INPUTS FROM KEYBOARD

Try using the control 'when [keypress] key pressed' and then 'set <variable name> to  = <variable name> + [keypress]' , you can repeat the control 10 times once for each digit. Then gather the presses into a collection variable as each key is pressed and have another button (sprite) using another 'when [keypress] key pressed' to confirm when the answer is ready for verification.

When [1] key pressed <--- Control
set collection to <(collection)+(1)> <-----Varibles + Numbers
When [2] key pressed <--- Control
set collection to <(collection)+(2)> <-----Varibles + Numbers + Variables

and so on for all ten number keys and then a simple

When [c] key pressed <--- Control

Do a little fluffy computer thinking hard sprite routine and then

If <(6) + (7)> = (collection) <---Control + Numbers + Variables
say "Correct! Rapperman Junior"  <---- Looks
Else
Say "Try Again" <-----Looks

or some such...rinse and repeat, hope that helped.

Offline

 

#3 2007-05-20 00:55:51

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: VARIABLE INPUTS FROM KEYBOARD

Look at my reverse-polish notation calculator:
http://scratch.mit.edu/projects/kevin_karplus/2164

It reads numbers from either the keyboard or the buttons on the screen.

You might also want to look at my print_decimal program at http://scratch.mit.edu/projects/kevin_karplus/2951
though it only does output, using sliders for inputs.

Offline

 

#4 2007-06-20 13:52:22

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: VARIABLE INPUTS FROM KEYBOARD

I have upgraded the RPN calculator
http://scratch.mit.edu/projects/kevin_karplus/2164
to allow "backspacing" on number entry with a left-arrow key.

It also now has e^x as an operator.

Offline

 

Board footer