Discuss Scratch

AE-Wolf
New to Scratch
8 posts

How do you get a sprite to stop moving immediately after a key is pressed?

Hi! I'm working on a game for school, but I can't figure out how to get the sprite to stop moving right after a key is pressed.
Here is the script and this is the entire program. All I need to do is fix this script and the program will be good to go. This project is due tomorrow, so I'll be willing to take any advice/suggestions. Thanks!

Last edited by AE-Wolf (March 15, 2016 19:09:29)

prettydarnamazing
Scratcher
100+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

when [space v] key pressed
repeat until <not <key [space v] pressed?>>

move (4) steps
end

When life gives you lemons, you freeze them and then throw 'em at the people who make life miserable.


AE-Wolf
New to Scratch
8 posts

How do you get a sprite to stop moving immediately after a key is pressed?

Thank you for the suggestion! I think I might have an idea of what to do, but I'm still stuck. This is the script I have:
when I receive [ yellow]
repeat until <key [ space] pressed?>
glide (1) secs to x: (-82) y: (77)
glide (1) secs to x: (217) y: (77)

end
broadcast [ yellowd]
deck26
Scratcher
1000+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

You can't interrupt a glide so for the two seconds you're gliding any space being pressed is being ignored.
EliBraz
Scratcher
5 posts

How do you get a sprite to stop moving immediately after a key is pressed?

deck26 wrote:

You can't interrupt a glide so for the two seconds you're gliding any space being pressed is being ignored.
That Makes No Sense
drmcw
Scratcher
1000+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

EliBraz wrote:

deck26 wrote:

You can't interrupt a glide so for the two seconds you're gliding any space being pressed is being ignored.
That Makes No Sense
Makes sense to me. The 2 glide blocks take 2 seconds to run so the space key detection in the repeat will only run every 2 seconds.

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
aarushm22
Scratcher
100+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

when green flag clicked
forever

if <key [right arrow v] pressed> then
forever
point in direction (90 v)
move (10) steps
forever

if <key [space v] pressed> then

stop [this script v]
end

end


end

end

when you are on scratch :: events hat 
have fun ::sensing
This song is awesome:
This is the singing part of a song and the insrumental song.
TheNonNameMouse
Scratcher
88 posts

How do you get a sprite to stop moving immediately after a key is pressed?

if <> then

glide (1) secs to x: (0) y: (0)
else

stop [this script v]
end

TheNonNameMouse
Head of Non Name Productions

aarushm22
Scratcher
100+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

when green flag clicked
repeat until <I multiply every thing by 5 forever>
forever multiply every thing in the project by (5 v)
end

Last edited by aarushm22 (March 15, 2016 20:32:46)


when you are on scratch :: events hat 
have fun ::sensing
This song is awesome:
This is the singing part of a song and the insrumental song.
drmcw
Scratcher
1000+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

To answer the original question assuming they still want to use glides then https://scratch.mit.edu/projects/101828381/

10 !
ScratchVaders or Galaga?
Maybe Eliza can help you decide?
deck26
Scratcher
1000+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

aarushm22 wrote:

when green flag clicked
forever

if <key [right arrow v] pressed> then
forever
point in direction (90 v)
move (10) steps
forever

if <key [space v] pressed> then

stop [this script v]
end

end


end

end
Three nested forever loops are never going to be a good idea!
prettydarnamazing
Scratcher
100+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

drmcw wrote:

EliBraz wrote:

deck26 wrote:

You can't interrupt a glide so for the two seconds you're gliding any space being pressed is being ignored.
That Makes No Sense
Makes sense to me. The 2 glide blocks take 2 seconds to run so the space key detection in the repeat will only run every 2 seconds.
makes sense to me too.

The reason it doesn't make sense is cause ur new to scratch. Deck26 is a pro.

When life gives you lemons, you freeze them and then throw 'em at the people who make life miserable.


AE-Wolf
New to Scratch
8 posts

How do you get a sprite to stop moving immediately after a key is pressed?

Thanks guys, this really helped!
LeftHandManGames
New to Scratch
25 posts

How do you get a sprite to stop moving immediately after a key is pressed?

this doesnt help it just moves over one step and stops until you press the script again how do you add an animation to it
deck26
Scratcher
1000+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

LeftHandManGames wrote:

this doesnt help it just moves over one step and stops until you press the script again how do you add an animation to it
Please create your own topic rather than necroposting. Share the project and describe your problem.
Dan3DTV
Scratcher
20 posts

How do you get a sprite to stop moving immediately after a key is pressed?

when green flag clicked
forever
if <key [space] pressed?> then
change x by (4)
end
end

when I receive [homework]
play sound [SCREAM]

im good scratcher
really good
scratchPro86
New to Scratch
15 posts

How do you get a sprite to stop moving immediately after a key is pressed?

I'm trying to stop a player from hitting an animal when the same button is pressed to start the player hitting the animal


Any help please??
I'm new to scratch
LeonLeontije26
Scratcher
1 post

How do you get a sprite to stop moving immediately after a key is pressed?

when green flag clicked
forever
if <> then
stop [ this script]
end
end

Last edited by LeonLeontije26 (April 11, 2021 09:15:19)

Tronche2Cake
Scratcher
100+ posts

How do you get a sprite to stop moving immediately after a key is pressed?

LeonLeontije26 wrote:

when green flag clicked
forever
if <> then
stop [ this script]
end
end

You're new to the forums I see. This post was made in 2016 and is considered dead. You posted a comment on it, which is called necroposting. It's annoying because it makes the post go back to the front of the forums even though people don't need it anymore.

Don't worry, we've all been there at some point, but check the date next time or forum lurkers will spam your account telling you not to necropost.

It's better to poop in the sink, than to sink in the poop.
-Scratch Cat, MIT graduate

sloth_yyy
Scratcher
8 posts

How do you get a sprite to stop moving immediately after a key is pressed?

lol

Powered by DjangoBB