Discuss Scratch

United_Snakes53
Scratcher
6 posts

How to get an Animation to stop when button is not held down?

Have a sprite that has a walking animation and I want it to use the animation while a button is held down. However I want it to immediately stop the walking animation as soon as the button is not pressed. The sprite however keeps doing the animation until it finishes the cycle, which I do not want. This is the script I´m using.
foreverifkeypressed?thenhideswitchcostumeto 0wait.07secselse

Last edited by United_Snakes53 (April 28, 2017 19:21:49)

United_Snakes53
Scratcher
6 posts

How to get an Animation to stop when button is not held down?

Sorry messed up.

foreverifkeypressed?thenswitchcostumetowaitsecsswitchcostumetowaitsecsswitchcostumetowaitsecsswitchcostumetowaitsecselseswitchcostumeto original
rpglurker
Scratcher
100+ posts

How to get an Animation to stop when button is not held down?

This block works for most programs, but the costume switch below the animation loop will not run until the wait period expires. Your code could not exit the loop early because the exit condition did not get checked until it finished the sequence. You can either change it to use next costume (see below -
it is better code anyway) or you could have another script running that “stops other scripts” with a stop block (this is kind of a cludgy fix)…

repeatuntilnotkeyright arrowpressed?nextcostumewait0.1secsswitchcostumetocostume1
United_Snakes53
Scratcher
6 posts

How to get an Animation to stop when button is not held down?

rpglurker wrote:

This block works for most programs, but the costume switch below the animation loop will not run until the wait period expires. Your code could not exit the loop early because the exit condition did not get checked until it finished the sequence. You can either change it to use next costume (see below -
it is better code anyway) or you could have another script running that “stops other scripts” with a stop block (this is kind of a cludgy fix)…

repeatuntilnotkeyright arrowpressed?nextcostumewait0.1secsswitchcostumetocostume1
It worked. Kinda.
I have other costumes in the sprite, and I want the walk animation to loop when the button is held down. With your script it goes to the other costumes when held down. Any suggestions please?
WolfCat67
Scratcher
1000+ posts

How to get an Animation to stop when button is not held down?

You can use this:
foreverwaituntilkeyinputpressed?nextcostume
Though not the best, it'll continually wait until you're using that button, at which point it will start the animation. Upon letting go, it'll immediately stop, as it only will continue if you press the button again.
CommunistToaster
Scratcher
3 posts

How to get an Animation to stop when button is not held down?

rpglurker wrote:

This block works for most programs, but the costume switch below the animation loop will not run until the wait period expires. Your code could not exit the loop early because the exit condition did not get checked until it finished the sequence. You can either change it to use next costume (see below -
it is better code anyway) or you could have another script running that “stops other scripts” with a stop block (this is kind of a cludgy fix)…

repeatuntilnotkeyright arrowpressed?nextcostumewait0.1secsswitchcostumetocostume1
I tried this and now pressing a does not allow the sprite to move on the x axis by -1. It's playing the animation perfectly though
-ShadowOfTheFuture-
Scratcher
1000+ posts

How to get an Animation to stop when button is not held down?

CommunistToaster wrote:

I tried this and now pressing a does not allow the sprite to move on the x axis by -1. It's playing the animation perfectly though

Please create a new topic for your own question. Thanks!

I'm leaving this open for now, since it doesn't seem to be completely resolved. In case the original poster is still looking for a solution, this might work, although it's a bit complicated and only works if those are the only scripts in the sprite:

whenclickedbroadcastmessage1whenIreceivemessage1broadcastmessage2forever. . . the animationwhenIreceivemessage2waituntilnotkeyKEYpressed?stopother scripts in spritewaituntilkeyKEYpressed?broadcastmessage1
SkyGuy354
Scratcher
19 posts

How to get an Animation to stop when button is not held down?

WolfCat67 wrote:

You can use this:
foreverwaituntilkeyinputpressed?nextcostume
Though not the best, it'll continually wait until you're using that button, at which point it will start the animation. Upon letting go, it'll immediately stop, as it only will continue if you press the button again.

I think that's the simplest one though

RememberForeverwaituntilKeyInputPressed?nextcostume

sorry i suck at scratchblocks
Freddyfangames1010
Scratcher
8 posts

How to get an Animation to stop when button is not held down?

If your making a game where you have a full walking animation with many costumes and when you stop holding the walking key it goes back to idle costume, go with my way. Let's start with the “When Green Flag Clicked” Events script block. Put a “Forever” Control script block under. Then put an “If ____ Then” Block under it. Inside that blank, put the “Key _____ pressed?” Sensing script block. Inside that blank, click the down arrow and select which key you would like to use. Next add a “Repeat Until ______” Control script block. Inside the blank, put the “Not ______” Operator script block. Inside that blank, put the “Key ______ pressed?” Sensing script block and select the same key as last time. Inside the “Repeat Until Not Key _______ pressed?” script, put the “Switch Costume to _____” Look script block. And in that blank, click the down arrow and select the costume you want for your first walking animation part. Under the “Switch costume to ______” script block, put the “Wait ___ secs” Control script block. in the blank put how long it will stay in that costume. Then keep going with the “Switch costume to _____” and “Wait _____ secs” Script blocks until you want your animation to restart. Now get ready for a new script. Put the “When Green Flag Clicked” Event script block. And under, put the “Switch costume to ____” look script block. In the blank put your idle costume. Get ready for another script. Put the “When Green Flag Clicked” Events script block. Under it, put the “Forever” Control loop script block. inside it put the “Wait until _____” Control script block. Inside the blank, put the “Not ______” Operator script block. Inside the blank, put the “Key _____ pressed?” Sensing script block. Inside the blank, put the same key as last time. Under it, put the “Switch costume to ___” inside the blank, put your idle costume. Hope it works out!
deck26
Scratcher
1000+ posts

How to get an Animation to stop when button is not held down?

Freddyfangames1010 wrote:

If your making a game where you have a full walking animation with many costumes and when you stop holding the walking key it goes back to idle costume, go with my way. Let's start with the “When Green Flag Clicked” Events script block. Put a “Forever” Control script block under. Then put an “If ____ Then” Block under it. Inside that blank, put the “Key _____ pressed?” Sensing script block. Inside that blank, click the down arrow and select which key you would like to use. Next add a “Repeat Until ______” Control script block. Inside the blank, put the “Not ______” Operator script block. Inside that blank, put the “Key ______ pressed?” Sensing script block and select the same key as last time. Inside the “Repeat Until Not Key _______ pressed?” script, put the “Switch Costume to _____” Look script block. And in that blank, click the down arrow and select the costume you want for your first walking animation part. Under the “Switch costume to ______” script block, put the “Wait ___ secs” Control script block. in the blank put how long it will stay in that costume. Then keep going with the “Switch costume to _____” and “Wait _____ secs” Script blocks until you want your animation to restart. Now get ready for a new script. Put the “When Green Flag Clicked” Event script block. And under, put the “Switch costume to ____” look script block. In the blank put your idle costume. Get ready for another script. Put the “When Green Flag Clicked” Events script block. Under it, put the “Forever” Control loop script block. inside it put the “Wait until _____” Control script block. Inside the blank, put the “Not ______” Operator script block. Inside the blank, put the “Key _____ pressed?” Sensing script block. Inside the blank, put the same key as last time. Under it, put the “Switch costume to ___” inside the blank, put your idle costume. Hope it works out!
There's a sticky topic at the top of the forum if you want to practice with Scratchblocks!
Carol_Studio
New Scratcher
1 post

How to get an Animation to stop when button is not held down?

Freddyfangames1010 wrote:

THANK YOU SO MUCH!!! This worked so well, and it's not glitchy. Your so easy to follow, and I'm super happy with my project! Thank you!!
QuirkyKittten
Scratcher
100+ posts

How to get an Animation to stop when button is not held down?

United_Snakes53 wrote:

Have a sprite that has a walking animation and I want it to use the animation while a button is held down. However I want it to immediately stop the walking animation as soon as the button is not pressed. The sprite however keeps doing the animation until it finishes the cycle, which I do not want. This is the script I´m using.
foreverifkeypressed?thenhideswitchcostumeto 0wait.07secselse
I can help. Instead of having nothing in the “Else” section, I would preferably put the “stop this script” like this:
whenclickedforeverifkeypressed?thenhideswitchcostumeto 0wait.07secselsestop this script

Last edited by QuirkyKittten (Jan. 20, 2020 17:33:42)

deck26
Scratcher
1000+ posts

How to get an Animation to stop when button is not held down?

QuirkyKittten wrote:

United_Snakes53 wrote:

Have a sprite that has a walking animation and I want it to use the animation while a button is held down. However I want it to immediately stop the walking animation as soon as the button is not pressed. The sprite however keeps doing the animation until it finishes the cycle, which I do not want. This is the script I´m using.
foreverifkeypressed?thenhideswitchcostumeto 0wait.07secselse
I can help. Instead of having nothing in the “Else” section, I would preferably put the “stop this script” like this:
whenclickedforeverifkeypressed?thenhideswitchcostumeto 0wait.07secselsestop this script
Please check the date before posting. This topic is old.
scratchPro86
New Scratcher
15 posts

How to get an Animation to stop when button is not held down?

But how do i make the sprite stop if i press space bar again?
deck26
Scratcher
1000+ posts

How to get an Animation to stop when button is not held down?

scratchPro86 wrote:

But how do i make the sprite stop if i press space bar again?
Please create you own new topic rather than necroposting. You can always cut and paste something from here or refer to this topic if necessary but more likely you can just share your project and say what you're trying to do.
-Esther
New Scratcher
1 post

How to get an Animation to stop when button is not held down?

.

Last edited by -Esther (Aug. 24, 2020 02:39:07)

HootDug
Scratcher
66 posts

How to get an Animation to stop when button is not held down?

Hey guys how do i post??!??! so i can create my pol lol
HootDug
Scratcher
66 posts

How to get an Animation to stop when button is not held down?

Can anyone help me? i need the costume 4 to stop until i stop holding the letter Here is the pic http://prntscr.com/v5qpkd
qucchia
Scratcher
100+ posts

How to get an Animation to stop when button is not held down?

Please create your own topic instead of posting on an old one
HootDug
Scratcher
66 posts

How to get an Animation to stop when button is not held down?

How do i make a topic??!?!?

Powered by DjangoBB