Variables
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.
Updating Variables (Game State Changes)
health = health - 20
coins = coins + 10
xp = xp + 50
print("Updated stats:", health, coins, xp)
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

