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