Step 2: Initializing Our Variables When the Game Starts

Goal:


Let’s write code that will make sure our variables all get reset properly whenever we restart the game.

Steps:

  1. Select the Backdrop.
  2. From Events, place a when green flag clicked block.
  3. From Control, place 2 set Lives to blocks.
  4. Change one of them to “Lives:” and set the number to 3.
  5. Set the other one to “Points:” and set the number to be 0.
  6. From Events, create a message called “GameStart!” and broadcast it.

Code:


Click to replay