Games16

Video Transcript

Until now, of course, at the meeting of our 2 objects or better sprites, nothing happens.

We want something to happen. We want - IF the lion meets the monkey THEN the game stops.

The "selection" programming structure must be used

I ask the specialist to give us some more insight into the matter ...

We all make decisions everyday all the time. If it rains I will take an umbrella. If it does not rain I will not take an umbrella with me.

All programming languages have commands that are executed only if a particular condition becomes true.

If this condition does not become true then these commands will never be executed.

The "selection" programming structure is expressed with an IF command.

The composition of the IF command in SCRATCH has the following formats:

IF "a condition is true" THEN

Perform these commands

As well as the form,

IF "a condition is true" THEN Perform these commands ELSE perform some other commands.

Let's take a look at an example in order to understand this better.

First of all, we have to consider that all of our instructions are in repeat blocks "Forever" as we want them running throughout the program.

From then and on, there are several IF. Let's see them in a row.

The first IF is not simple. An IF that isn't simple is one that contains the part ELSE.

In this case, throughout the game, either the instructions that take place here or the instructions that take place here, will be executed.

We see from the beginning that the ghost does not touch Gas. So the command that will be executed is: "Say I will catch you and eat you"

From the next IF the command "move 30 steps" will be execute only if the space bar is pressed.

The same thing will happen with the commands “point”.

The one command will be executed only by pressing the left arrow on the keyboard and the other one by pressing the right arrow.

If the space bar, the left and the right arrow buttons are never pressed the IF instructions will never be executed.

Let's run the script in order to see the outcome of this scenario.

The "Say I will catch you and eat you" message runs again and again and gives the impression that it is permanently on.

Let’s push the space bar button.

The left arrow.

And the right arrow..

Let’s press the space bar as many times as needed in order for Gas to meet the ghost.

Now you see how the first part of the IF is executed.

The structure of the selection is necessary in programming.

The games you will create will contain many IF instructions. Both simple IF and IF - ELSE.

It is crucial to understand them very well and use them easily.

So if the lion touches the monkey, we want everything to stop.

The appropriate instruction is on the "Control" pallet.

Of course, the IF instruction should be within the repetition in order to be valid throughout the game.

Let’s put it in the right place and test it in the script.

Very nice. Our game is pretty advanced. In our next lesson we will see even more things.

See you soon..

Scroll to Top