Variables

STEP 1 — Variables: Your Game’s Memory Slots

Alright young developer, today your game finally gets the ability to remember things. Before this, your game had the memory of a goldfish. Now? It’s getting an upgrade — like installing a brain expansion pack. Welcome to variables.

What Are Variables?

Variables are labeled storage boxes your game uses to keep track of important stuff:

  • player health
  • coins
  • XP
  • player name
  • whether the boss is alive

If your game were a backpack, variables are the pockets. Some pockets hold snacks. Some hold pencils. Some hold… whatever that sticky thing is. But they all store something.

Why Variables Matter

Without variables, your game can’t:

  • track score
  • update health
  • store player choices
  • remember anything

Imagine a game where every time you get hit, your health resets to 100.
That’s not a game — that’s a glitchy hug simulator.

Variables make your game react, change, and feel alive.

Naming Variables Like a Pro

You can name your variables anything…
but please don’t do this:

x = 10
thingy = "Bob"
idk = True

Your future self will cry.

Good names = readable code = fewer headaches.


Code Example — Player
Stats Stored in Variables

player_name = "Nova"
health = 100
coins = 25
xp = 0
is_alive = True

print(player_name, health, coins, xp, is_alive)

Your game now remembers things AND updates them — like a responsible adult.

Try yourself.

Updating Variables (Game State Changes)

health = health - 20
coins = coins + 10
xp = xp + 50

print("Updated stats:", health, coins, xp)
Try yourself.

Your game now remembers things AND updates them — like a responsible adult.


Practice (Your Turn!)

Mini Challenge — Island Survival

Challenge:

Create variables for a game about surviving on a mysterious island.

Store:

  • player name
  • hunger level
  • water supply
  • number of coconuts
  • whether it’s daytime
Modify and Run