Lesson 1 · Creative Coding
A box that remembers a value.
Your loop challenge ended with a puzzle: how can a sprite count 1, 2, 3 when a loop repeats the same thing every time?
Here's the answer. The program needs somewhere to remember a value between repeats.
That somewhere is a variable — a named box holding one value. Put something in, look at it later, replace it whenever you like.
Every variable has two parts:
score, lives, timer, speedTwo blocks do almost everything:
set [score] to 0 — replace whatever is in the boxchange [score] by 1 — adjust what's already thereUse set to start fresh at the beginning of a game. Use change to count up or down as it's played. Mixing these up is a very common bug — set score to 1 every time a mango is caught leaves the score stuck at 1 forever.
5 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.