Step 3: Pack Your Backpack ๐
Real adventure games let you pick things up and use them later. Time for an inventory! ๐
An inventory is just an empty list that grows:
inventory = [] # empty backpack
inventory.append("key") # found a key!
inventory.append("candle") # ooh, a candle
print(inventory) # โ ['key', 'candle']
.append() adds one thing onto the end of a list.
Later you check what you're carrying with the word in:
if "key" in inventory:
print("๐ The rusty key fits! The door swings open.")
else:
print("๐ Locked tight. If only you had a key...")
That's the magic move: something the player did way earlier changes what happens now. Suddenly your story has a memory. ๐ง
Your mission
Keep your story and add:
inventory = []at the very top- At least one item to find โ
inventory.append("key")on one of the paths - A locked door at the end that only opens
if "key" in inventory - Print the backpack somewhere so the player can see what they have
Now the left door actually matters. ๐
Your code
Press โถ Run to see what your code does!