Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Hiding objects when pressing [stop]?
- krumthebarbarian
-
New Scratcher
2 posts
Hiding objects when pressing [stop]?
Hi there. So in the game I'm working on, I have a hit box of sorts that I've made to be hidden/transparent when appropriate, however, if you hit the stop button (as in, the one next to the green flag) it'll reappear. I intent to have a title/game over page so the stop button isn't actually meant to be touched, but regardless, I don't want the ugly behind-the-scenes stuff to be shown if someone clicks it by mistake. Is there a way I can fix this? Thanks in advance. 

- sdsquires
-
Scratcher
100+ posts
Hiding objects when pressing [stop]?
You could put in a script that workarounds the stop button and then put something else in front (like the thumbnail), which you can do with this script:
when green flag clicked
forever
set [Stop detector v] to ((timer) + (0.1))
end
when [timer v] > ((Stop detector))
if <[timer] > [(Stop detector)]> then
...
end
Last edited by sdsquires (June 5, 2020 01:49:09)
- Paigeri
-
Scratcher
500+ posts
Hiding objects when pressing [stop]?
Hi there. So in the game I'm working on, I have a hit box of sorts that I've made to be hidden/transparent when appropriate, however, if you hit the stop button (as in, the one next to the green flag) it'll reappear. I intent to have a title/game over page so the stop button isn't actually meant to be touched, but regardless, I don't want the ugly behind-the-scenes stuff to be shown if someone clicks it by mistake. Is there a way I can fix this? Thanks in advance.I think I know what you're saying. If you want something like a thumbnail almost, you can use this script:
when green flag clickedThis way you can have a picture, or I suppose in your case a few sprites, go in front of everything else, creating like a thumbnail!
show
set [ ghost ] effect to (100)
go to front
- krumthebarbarian
-
New Scratcher
2 posts
Hiding objects when pressing [stop]?
You could put in a script that workarounds the stop button and then put something else in front (like the thumbnail), which you can do with this script:when green flag clicked
forever
set [Stop detector v] to ((timer) + (0.1))
endwhen [timer v] > ((Stop detector))
if <[timer] > [(Stop detector)]> then
...
end
Hi there. So in the game I'm working on, I have a hit box of sorts that I've made to be hidden/transparent when appropriate, however, if you hit the stop button (as in, the one next to the green flag) it'll reappear. I intent to have a title/game over page so the stop button isn't actually meant to be touched, but regardless, I don't want the ugly behind-the-scenes stuff to be shown if someone clicks it by mistake. Is there a way I can fix this? Thanks in advance.I think I know what you're saying. If you want something like a thumbnail almost, you can use this script:when green flag clickedThis way you can have a picture, or I suppose in your case a few sprites, go in front of everything else, creating like a thumbnail!
show
set [ ghost ] effect to (100)
go to front
Hey, thanks so much for replying! I may have not been clear, the button that I'm referring to is the one off of the project entirely, that shows up right next to the green flag in the top left hand area above the project itself. Pressing that reveals my hit box sprite that I don't want to be seen even though it remains hidden during any game activity. Essentially, I want my hit box to remain hidden if, for example, someone wanted to stop the game before it was finished and pressed that stop sign.
If that is what you are referring to, and I'm just an idiot (entirely possible, lol), I did try your scripts just in case and they didn't work out for me. The timer still stops when the stop button is pressed.
- super_crazy
-
Scratcher
100+ posts
Hiding objects when pressing [stop]?
Clicking on the ‘stop’ button (next to the green flag) automatically clears all graphic effects on sprites. As far as I know that can't be changed or turned off. So if you really want to make sure that the hitbox remains ‘hidden’ you'll need to do something similar to what sdsquires showed.
The timer never actually stops, even if the ‘stop’ button is pressed or the ‘stop all’ block is used. So always resetting the timer and using the ‘when (timer)’ hat block we can check if the project has stopped (by the user pressing the ‘stop’ button)
The best way to go about this is similar to what sdsquires showed in their post:
Also note: if you are resetting the timer elsewhere in your code then this might not work 100%
The timer never actually stops, even if the ‘stop’ button is pressed or the ‘stop all’ block is used. So always resetting the timer and using the ‘when (timer)’ hat block we can check if the project has stopped (by the user pressing the ‘stop’ button)
The best way to go about this is similar to what sdsquires showed in their post:
That code should kinda work for what you want. However, if the user presses the stop button twice it will show the hitboxes again. To stop that either make sure to actually hide the hitboxes the first time or in the ‘when (timer)’ hat block, make another forever loop and change the ‘restart_time’ variable the same as before.when green flag clicked
forever // Constantly change the value of 'restart_time' to the timer plus a little bit
set [restart_time v] to ((timer) + (0.1)) // You can set the '0.1' to whatever you want
end
// As soon as the 'stop' button is pressed, the above code will stop running meaning 'restart_time' won't update
when [timer v] > (restart_timer) // Put this in the hitbox sprite
set [ghost v] effect to (100)
code to run when 'stop' is pressed :: grey
// Because 'restart_time' is no longer changing the value of the timer will quickly become greater then
// the 'restart_time' variable and cause the above block to run
Also note: if you are resetting the timer elsewhere in your code then this might not work 100%
Last edited by super_crazy (June 5, 2020 04:46:26)
- Discussion Forums
- » Help with Scripts
-
» Hiding objects when pressing [stop]?



