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

#1 2007-05-15 00:27:48

rszrama
Scratcher
Registered: 2007-05-15
Posts: 25

Do...While

Am I missing a control structure that would allow me to move a sprite in the direction specified by the arrow key until that key is released?  I tried:

when right arrow pressed
point in direction 90
forever if key right arrow pressed
-move 1 steps

That gives me continuous movement while the right arrow key is pressed.  But if I release the arrow key, that script still appears to be "activated" in that it's still highlighted.  I have a mirror script for walking left, but the next time I then try to move right, because the right arrow script is still highlighted it will move the sprite right but not change the picture.

--------------

Ok, 15 more seconds passed, and I figured out how to do this, but I'm leaving the original text because it seems to me like my original code should have worked.  I fixed it by splitting the point in direction and forever if into two separate "when key pressed" controls.  It seems this should work under the one control.

Also, as the notes say, I noticed that Scratch was still trapping keypresses to move my sprite in the dialog box that popped up for me to submit my project.  I'd imagine since it's out of focus that it shouldn't be running the program still.

EDIT: I removed the test project to prevent clutter and replace it with an actual walk around/jump demo: http://scratch.mit.edu/projects/rszrama/3188

Last edited by rszrama (2007-05-15 01:33:40)

Offline

 

#2 2007-05-15 00:35:12

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

Re: Do...While

Try using the new

repeat until not right arrow pressed
   move 1 steps

instead of
forever if right arrow pressed
   move 1 steps

(I'm  going to encourage my students to eliminate forever loops whenever they can)

Offline

 

#3 2007-05-15 00:47:34

rszrama
Scratcher
Registered: 2007-05-15
Posts: 25

Re: Do...While

Where are you finding "repeat until not"?  I just downloaded from here tonight... is there a chance it wasn't the latest version?

EDIT:  Never mind, found the not in the Numbers section if that's what you were referring to.

Last edited by rszrama (2007-05-15 01:19:48)

Offline

 

#4 2007-05-15 01:48:54

stratolab
Scratcher
Registered: 2007-04-17
Posts: 11

Re: Do...While

Kevin_karplus- Why do you encourage students to eliminate forever loops?  Do you find that Scratch is slowing down from too many loops?  Or it just feels inefficient?

Offline

 

#5 2007-05-19 01:50:53

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

Re: Do...While

I've not made a big deal about it (as an after-school volunteer teacher, I don't have that much influence over them---Tech Club has to be *fun*).  But my objection to forever loops is only partly from efficiency---it is also from a traditional computer-science view, where infinite-looping is almost always an error.  Getting kids to think about exit conditions is an important part of teaching programming.

Offline

 

Board footer