Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » my code no works
- zemzemmy
-
Scratcher
30 posts
my code no works
HELLOOOOOOO
so im making an ending game project and im tryna get some code to work for my ending game project
i wanted to make an ending where you give the character a ball but then you snatch the ball out of his hands
but when the animation plays it just dosent work (very rarely works)
i have been looking for help for a very long time but i cant find any
here is the project link: https://scratch.mit.edu/projects/1345879338/
thank you and have a good day
so im making an ending game project and im tryna get some code to work for my ending game project
i wanted to make an ending where you give the character a ball but then you snatch the ball out of his hands
but when the animation plays it just dosent work (very rarely works)
i have been looking for help for a very long time but i cant find any
here is the project link: https://scratch.mit.edu/projects/1345879338/
thank you and have a good day

- DanDanbingobam
-
Scratcher
54 posts
my code no works
The reason your project rarely works is because your scripts are fighting each other at the exact same time! This is called a “race condition” in programming.
In your third image, your leftmost script runs a timed animation sequence (Good 1 -> Good 2 -> Good 3). At the exact same millisecond, your middle and right scripts are checking for mouse clicks to trigger the alternative endings (Oops, Bad Ending, etc.). When you click to snatch the ball, the click script successfully switches the costume to Oops 1. However, because your animation script is still running loop instructions in the background, it instantly overrides your click on the very next frame to continue its own timeline. This is why it looks like your click didn't do anything, and it causes multiple ending sounds to play over each other.
To fix this, you need to tell your main animation script to stop running the moment a player interacts or triggers an alternative ending. First, create a new Variable called and set it to 0 when the green flag is clicked. Next, inside your leftmost animation script, put an if block around your wait blocks so that the timer animation can only move forward if < (Ending Triggered?) = 0 >. Finally, in your mouse-interaction and snatching scripts, make the very first action set to 1 and add a stop block right away. This ensures that once a player goes down the “snatch the ball” path, the main animation timeline safely freezes and lets your secret ending play out perfectly!
In your third image, your leftmost script runs a timed animation sequence (Good 1 -> Good 2 -> Good 3). At the exact same millisecond, your middle and right scripts are checking for mouse clicks to trigger the alternative endings (Oops, Bad Ending, etc.). When you click to snatch the ball, the click script successfully switches the costume to Oops 1. However, because your animation script is still running loop instructions in the background, it instantly overrides your click on the very next frame to continue its own timeline. This is why it looks like your click didn't do anything, and it causes multiple ending sounds to play over each other.
To fix this, you need to tell your main animation script to stop running the moment a player interacts or triggers an alternative ending. First, create a new Variable called and set it to 0 when the green flag is clicked. Next, inside your leftmost animation script, put an if block around your wait blocks so that the timer animation can only move forward if < (Ending Triggered?) = 0 >. Finally, in your mouse-interaction and snatching scripts, make the very first action set to 1 and add a stop block right away. This ensures that once a player goes down the “snatch the ball” path, the main animation timeline safely freezes and lets your secret ending play out perfectly!
- 10goto10
-
Scratcher
1000+ posts
my code no works
I was thinking a truth table approach might help where each of the possibilities are handled in your different scripts. I made this remix https://scratch.mit.edu/projects/1381040429/ (has comments).
- Discussion Forums
- » Help with Scripts
-
» my code no works