Creative Coding (Day 2)

Events

Events are used to start a script. Every script MUST start with an event block.

The “when green flag clicked” event is commonly used to start a game.

One of the most often used event is the “when space key pressed” block. This starts a script when the “space” key is pressed. We can also change it to start a script when another key is pressed, such as the “up arrow” or “down arrow”. This is usually used to control our game character. In the fruit catcher game, we use it to move the basket left and right.

One special event is the “when I receive message” event. We’ll learn about it in day 3.

Control and Sensing

The “touching” block is often combined with the “if then” block. This allows the sprite to do something if it touches another sprite. In the example above, it will say “Hello!” if it touches the Apple sprite.

In the blocks palette, the “touching block” appears as “touching mouse pointer?”. Remember to change “mouse pointer” to the sprite we want to detect!

The “forever” block repeats something forever (…or at least until we click the stop button). If we didn’t have a “forever”, the program above will only check once, then it will end almost immediately.

Operators

The “pick random 1 to 10” gives us a random number between 1 to 10. We can change it to give us any number range we want (eg. -100 to 100). This is useful to mix things up for our game. Without it, the game will always be the same!

Quiz