I need a script that tells Scratch what the user input. It'll be a number.
The code is for Basic.
The line of code in basic:
Input N
Print " The number is (n-4)/2."
help would be loved.
Offline
Hi 300pockets,
You can do this by using the "When __ key pressed" block, and keeping track of the number typed by the user in a variable. So for example, say the variable is called "user number." Then you could have the following scripts:
When 1 key pressed
set user number to 1
When 2 key pressed
set user number to 2
When 3 key pressed
set user number to 3
etc..
Does this help?
Thanks,
Tammy
Offline
300pockets wrote:
Input N
Print " The number is (n-4)/2."
Maybe you can do this:
1. Make a variable called N.
2. Right-click on the monitor of N (in the stage), and choose "Show slider".
3. Another right-click to set the slider min and max value.
4. Draw a new sprite, called "OK Button" (or something else).
5. You also need another sprite to tell the result (eg. the Cat).
Your stage will look like that:
Here's the OK button's script:
And Cat's script:
Of course, it's just an example.
Offline
Similar to using the slider - make the variable "input" visible on screen then:
When up arrow pressed
- increase input by 1
When down arrow pressed
- increase input by -1
When enter pressed
- say " The number is..." for 2 seconds.
- say (n-4)/2 for 2 seconds.
(though you may want to look at alternatives to "say", like Kevin's excellent number printing script:
http://scratch.mit.edu/projects/kevin_karplus/2951)
Offline
If you want to parse typed number input, take a look at my RPN_calculator. you can't catch minus signs and periods from the keyboard, though, as they did not provide that capability in scratch.
http://scratch.mit.edu/projects/kevin_karplus/2164
Offline