A box with a name

ReadingKeeping count

Your game counts coins for you. It also knows how many lives are left and how long you have played. How does a game remember a number?

It uses a variable. In this chapter you make your own.

A box with a name

A variable is like a box with a name on it. The box holds one number. You can look in the box, and you can change what is in it.

In Splat Labs, the scripts that run your game are written in Splat Script. In Splat Script, a variable's name starts with @.

You writeWhat happens
@coins is 12The box called coins now holds 12
@coins goes up by 1The box holds 1 more than before: 13
@coins goes down by 3The box holds 3 fewer: 10

Sums with variables

A variable can be used in a sum, just like a number.

You writeIf @coins is 12The answer
@left is 30 - @coins30 − 12@left is 18
@double is @coins * 212 × 2@double is 24
@share is @coins / 412 ÷ 4@share is 3

Scripts use * for times and / for divide. That is how sums are typed on a keyboard, which has no × or ÷ key.

You don't need to know scripts

This course gives you every script. You read it, change a number, and see what happens.