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

#1 2007-06-02 21:15:40

300pockets
Scratcher
Registered: 2007-05-27
Posts: 8

Help! Input in Scratch?

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.


I am the original 300pockets of myspace.com/300pockets. I am quite young, and my interests include astrophysics, reading fantasy novels, and using programs such as Bryce5 to create 3D landscapes. I enjoy creating oceans, although I am afraid of swimming in the real seas. My cowardice does not overcome my sense for beauty.

Offline

 

#2 2007-06-02 22:58:28

tammy
Scratcher
Registered: 2007-03-07
Posts: 57

Re: Help! Input in Scratch?

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

 

#3 2007-06-03 02:41:42

bernatp
Scratcher
Registered: 2007-03-07
Posts: 49

Re: Help! Input in Scratch?

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:
http://scratch.inf.elte.hu/stuff/count_stage.gif

Here's the OK button's script:
http://scratch.inf.elte.hu/stuff/count_ok.gif

And Cat's script:
http://scratch.inf.elte.hu/stuff/count_cat.gif

Of course, it's just an example.

Offline

 

#4 2007-06-03 03:57:37

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: Help! Input in Scratch?

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)


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#5 2007-06-03 11:19:53

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

Re: Help! Input in Scratch?

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

 

Board footer