Controlling When Scripts Run
In Chapter 10, we showed you how to start scripts by clicking them in the Scripts Area. Most of the time, you’ll want your scripts to run automatically when certain things happen, such as a player pressing the Fire key.
This is where the Control blocks come in: They allow you to trigger scripts to run when a particular event happens, such as a sprite hitting another sprite or a key being pressed. You use the Control blocks to craft the rules and instructions that govern how your game works.
Using the green flag to start scripts
One of the Control blocks is particularly useful for starting your game and synchronizing your scripts across all your sprites. Above the Stage are two buttons: a green flag and a red stop button. The green flag is used to start scripts running, and you can use a Control block to detect when it’s clicked. This Control block has a curved top on it because no other block can go above it, but it has a notch underneath so you can join motion, looks, sound, or other blocks to it. You can put scripts that are triggered by the green flag being clicked into all your sprites, so clicking the flag makes it easy to start scripts on different sprites at the same time.
At the end of a game, aliens and ships could be anywhere, so at the start of the game, you need to reset each sprite to its starting position. For the player’s ship, you need to reset the X position to the center of the screen, set the Y position near the bottom of the screen, ...