Step 1
Creating a global variable
We'll start with creating the variable that will keep count of how many lives we have. This will be a number variable - remember that a variable is a piece of data that the program will remember.
Variables can be global, properties, or local. So far we've dealt with property variables which retain their value inside a script, and local variables which retain their value inside a single block.
This time we're going to use a global variable. Global variables retain their value across scripts and across levels, so when we use a global variable for the player's lives, the player can lose lives on Level 1, and this amount of lives will carry across to Level 2 and beyond.
To create a new global variable, go to the Variables tab, and from under the Global heading, grab the variable block named "set true/false i to". Drag this block to the bottom of the "When created" stack of blocks.
To make this into a new variable, click "i" and select New variable... Name this variable lives.
This "lives" variable can be any kind of variable -- you can keep track of many different kinds of data -- it could be a number, or a boolean (true/false), or text, or a colour, etc. We want to set it to a number, so click on "true/false" and select number.
Now we're going to set the amount of lives the player starts off with. Grab the number block (0) from the Operators tab, and drop it in the empty slot. Change this number to 4.