Discuss Scratch

JenniferGenius
Scratcher
2 posts

How do I make a script only run one time?

I have a game where the background will change many times. The background will be reused.
So, on the first time the background is seen, I want the sprite to say something.
But only the first time.
How do I do this?
epicbattler3
Scratcher
55 posts

How do I make a script only run one time?

set [seenBackground v] to [0]
if <<(backdrop #) = [backdrop number you want it to be]> and <(seenBackground ) = [0]>> then
say [hello!] for (2) secs
set [seenBackground v] to [1]
end

This should work, since if it runs another time it won't run this script due to seenBackground being 1

░▄▀▄▀▀▀▀▄▀▄░░░░░░░░░
░█░░░░░░░░▀▄░░░░░░▄░
█░░▀░░▀░░░░░▀▄▄░░█░█
█░▄░█▀░▄░░░░░░░▀▀░░█
█░░▀▀▀▀░░░░░░░░░░░░█
█░░░░░░░░░░░░░░░░░░█
█░░░░░░░░░░░░░░░░░░█
░█░░▄▄░░▄▄▄▄░░▄▄░░█░
░█░▄▀█░▄▀░░█░▄▀█░▄▀░
░░▀░░░▀░░░░░▀░░░▀░░░
awesome-llama
Scratcher
1000+ posts

How do I make a script only run one time?

It can also be done by using a wait until block and having it run from a green flag hat (since the green flag is only clicked once to start the project).

when green flag clicked
... // make sure to set the backdrop to something other than the one you are checking for***
wait until <(backdrop [name v]::looks) = [desired backdrop]>
... // the script you want to run once

*** To prevent the “click the green flag twice” glitch. You want to make sure that the backdrop is reset before you check for a certain one, just in case the backdrop hasn't been set yet and clicking the green flag ends up running the script immediately.


bluedragon8633
Scratcher
1000+ posts

How do I make a script only run one time?

There's a “stop this script” block that you could activate after the sprites says something.

Game with No Sprites: https://scratch.mit.edu/projects/710922832/
Riddle School 5- Tile Puzzle 1: https://scratch.mit.edu/projects/625744508/
RIP Adobe Flash Player

Yokan is coming.

Powered by DjangoBB