Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Stopping variable at certain point
- thecomicallyawesome
-
New Scratcher
2 posts
Stopping variable at certain point
Hello! I am trying to make my variable “nights” stop after 6, but like, make the button stop working, is there a way to help? 
My code goes like this:

My code goes like this:
when this sprite clicked
hide variable [ nights]
set [ nights] to ((nights) + (1))
if <[(nights)] > [6]> then
set [ (nights)] to ((6) - (1))
end
broadcast [ continue]
Last edited by thecomicallyawesome (Oct. 12, 2026 02:29:05)
- FancyTigerDustBall
-
Scratcher
77 posts
Stopping variable at certain point
You could put the whole thing in an “if” block:
when this sprite clicked
if <(nights) < [7]> then
do stuff
end
- thecomicallyawesome
-
New Scratcher
2 posts
Stopping variable at certain point
Like this?
when this sprite clicked
hide variable [ nights]
set [ nights] to ((nights) + (1))
if <[nights] < [7]> then
stop [ nights]
end
Last edited by thecomicallyawesome (Oct. 12, 2026 03:32:09)
- Blobfish_Industries
-
Scratcher
100+ posts
Stopping variable at certain point
You don't need to use
and you don't need to hide the variable every time it is clicked unless it gets shown between clicks.
set [nights v] to ((nights) + (1))because you can use a change block like this:
when this sprite clicked
if <(nights) < [7]> then
change [nights v] by (1)
broadcast [Continue v]
end
and you don't need to hide the variable every time it is clicked unless it gets shown between clicks.
- UncappedCyanMarker
-
Scratcher
26 posts
Stopping variable at certain point
If you want “nights” to stop changing by 1 if its value is already 6, use this:
when this sprite clicked
if <(nights) > [6]> then
broadcast [continue v]
else
change [nights v] by (1)
end
Last edited by UncappedCyanMarker (Yesterday 04:33:57)
- ITS_DINO_XD
-
Scratcher
100+ posts
Stopping variable at certain point
repeat until <(nights) = [6]>
change [nights v] by (1)
end
- Discussion Forums
- » Help with Scripts
-
» Stopping variable at certain point