Instead of having the duplicate code from the “When Green Flag clicked”, I simply moved ALL of the initialization code into a “when I receive reset” then placed “broadcast reset” under the green flag in the Game sprite.
For the Gobo, I added the ‘drop gift’ forever loop under the pen down on each Gobo freeing up one green flag event (i heard those can cause lag if you have a lot - not a factor for a small game like this, but always a good idea to think of optimizations).
Likewise I moved all of the Gobo initialization (formally under a green flag) to a “when I receive reset” header.
Reasoning: Regardless if you are starting by hitting green flag, or resetting from win screen, it will re-initialize everything using a single broadcast instead of multiple green-flag clicks that introduces needless redundancy to the code.
After winning it will stay in the “forever loop” causing a reset any time space is pressed after the initial win is met.
(Downloaded the course file to ensure it wasn’t something I did and it is there too, as well in the final “adding polish” download)
- I created a variable for winScreen only named “GameOver”
- In the “green flag click” event, I set it to false just before the “hide” event.
- In the start of the definition for the GameOver MyBlock, I set it to True (the only reason the GameOver block will run is if we hit a game over condition and it will run regardless who won).
- I then replaced the Forever loop with “repeat until GameOver = false” and added a “set GameOver to false” at the end of the “If key space pressed? then” block
Reasoning: It will function exactly as a “forever” loop as long as GameOver is true (set at the start of the GameOver MyBlock). As soon as it broadcasts the “reset”, it is set to false ending the loop on the “hide” block. This not only solves the bug, but also saves on resources by preventing it from looping needlessly.
My original solution was to add a “and” condition to the “if key space pressed” to verify GameOver was true, but it didn’t end the forever loop. My new solution not only simplifies the conditional of the code, but also prevents wasted processing.
Image of my final code related to this bug for visual reference: