Updating Game State
Welcome back, young developer.
Your variables are cool and all… but right now they’re just sitting there like:
“Hi, I’m health = 100. I do nothing. I contribute nothing. I am a decorative number.”
Not anymore.
Step 3 is where your game becomes ALIVE.
This is where numbers change, stats update, and your game starts acting like a real game instead of a digital potato.
What Does “Updating Variables” Mean?
It means your game can react when things happen.
- Player gets hit → health goes down
- Player finds treasure → coins go up
- Player levels up → XP increases
- Player falls off a cliff? Boolean says “nah, they’re not alive anymore.”
Your game becomes dynamic — like a teenager’s mood swings, but with math.
The Magic Formula
Every update follows the same pattern:
variable = variable + something
OR:
variable = variable - something
Or: the classic gamer move:
variable = variable * something
This is how games update stats.
Code Example —Your Player Takes Damage, Finds Coins, and Levels Up
health = 100
coins = 25
xp = 0
health = health - 20
coins = coins + 10
xp = xp + 50
print("Updated stats:", health, coins, xp)
Your game is now reacting to events like a pro.
Why This Matters
Without updating variables, your game would be like:
Picks a random item from a list.Great for choosing:
Updating variables = your game actually works.
Practice (Your Turn!)
Mini Challenge — Survival Update
Challenge:Start with these variables:
- health = 80
- stamina = 50
- arrows = 12
Update them so that:
- player takes 30 damage
- uses 3 arrows
- regains 20 stamina


