Variables were briefly introduced in the session on turtle graphics and are a fundamental part of Scratch and computer programming in general. Variables are introduced as simple numbers which can be made available to the whole application or kept private for a particular sprite. The speed of a sprite might be a private variable whereas the score in a game might be available to all sprites.

The video tutorial introduces a private variable to keep track of the speed of a sprite which can be increased and decreased by pressing keys. The score is maintained in a global variable which is increased each time the sprite collides with a target and the background changes depending on the level reached. Control blocks that use programming constructs such as ‘increase the speed only if the speed is less than 10’ or ‘show a different background if the score is greater than 3’ are introduced.

Random numbers are introduced as a useful means for starting off sprites in different positions each time a game starts or for creating unpredictable behaviour.

22/06/2024 10:01:27