Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How does exactly Stop All work?
- s_federici
-
Scratcher
500+ posts
How does exactly Stop All work?
After the Stop All block is executed other blocks are still executed before all scripts really stop running. How can I know exactly what blocks are run after Stop All? I suppose they are “hanging” blocks/scripts. But can I know exactly which blocks/scripts?
- CST1229
-
Scratcher
1000+ posts
How does exactly Stop All work?
I'm pretty sure *everything* stops when a stop all block is run. It's just that some scripts may run before a script that contains the stop all block.
- s_federici
-
Scratcher
500+ posts
How does exactly Stop All work?
I'm pretty sure *everything* stops when a stop all block is run
I verified that this is not the case, at least not immediately. After the Stop All block is run, several blocks/scripts keep running. You can have a look at the sample project https://scratch.mit.edu/projects/679565792/.
In this project, if you keep the SPACE key pressed, the line gets consumed. Then, if you click the green flag again, the line goes full, but the project stops. This means that both the GOTO block and the script containing the STOP ALL block are run. But the GOTO block cannot be run BEFORE the script containing the STOP ALL block, otherwise the STOP ALL block would not be executed (the condition would be false). So, it can only run AFTER the GOTO block.
Last edited by s_federici (April 23, 2022 09:11:33)
- mybearworld
-
Scratcher
1000+ posts
How does exactly Stop All work?
If I remember correctly, Scratch (obviously) can't do two things at once. Therefore, it just “cycles” between scripts. Therefore, after the line has been consumed and the green flag gets clicked, the code might do this:
I'm pretty sure this is the cause.
//pseudo code updateScreen(); position.set(0, 170); if (position.x < -470) { // This will STILL be true, as the screen will not have refreshed stopAll(); } updateScreen() // NOW the screen gets refreshed, but no scripts continue, as "stopAll();" was ran.
- imfh
-
Scratcher
1000+ posts
How does exactly Stop All work?
Want to really see something weird? Switching the hats on the loops (so the on on the stop is on the move blocks, and the one on the move blocks is on the stop blocks) and try it again.
Here's what's happening (without switching the hats):
So basically, the reason the move script gets to run a single time after the stop block runs. Everything doesn't stop until the screen updates.
Here's what's happening when you do switch the hats:
When you switch the hats, it makes the move block run before the stop block. So when the move block changes the position to -472, the stop block run immediately afterwards and is able to stop everything before the move blocks have a chance to run again.
You can check the order by getting rid of the forever loops and replacing them all with set variable to. The one which runs last will determine the final value of the variable.
If you want to pick the order everything runs, try something like this:
Here's what's happening (without switching the hats):
Line is not less than -470
Line moves
...
Line is equal to -468
Line moves (to -470)
Screen updates
Line is equal to -470 (not less that, so don't stop)
Line moves (to -472)
Screen updates
Line is equal to -472 (less than, so stop)
Line moves (to -472)
Screen updates, everything stops
Here's what's happening when you do switch the hats:
Line moves
Line is not less than -470
...
Line moves (to -470)
Line is equal to -470
Screen updates
Line moves (to -472)
Line is equal to -472 (less than, so stop)
Screen updates, everything stops
You can check the order by getting rid of the forever loops and replacing them all with set variable to. The one which runs last will determine the final value of the variable.
If you want to pick the order everything runs, try something like this:
when green flag clicked
forever
broadcast [Move If v]
broadcast [Stop If v]
when I receive [Move If v]
if <...> then
... // This will run first
end
when I receive [Stop If v]
... // This will run second
- Discussion Forums
- » Advanced Topics
-
» How does exactly Stop All work?