Sub topic 8
Unlock Conditions and Prerequisites
This chapter assumes you understand basic player progression, Python dictionaries, sets, functions, and Boolean conditions. An unlock condition is a rule that decides whether a player can access content. A prerequisite is something the player must already have or complete before the rule passes.
Unlocks connect progression to content. A level requirement can pace difficulty, while a quest or item requirement can make the world feel connected. Good gates guide players without making them repeat unrelated work.
Model an Unlock as Data
Keep unlock rules separate from the code that checks them. Each content entry can define only the conditions it needs.
| Condition | Example | What it controls |
|---|---|---|
| Level | Level 5 | Player power or expected experience |
| Completion | Finished `forest` | Narrative or content order |
| Item | Owns `silver_key` | Exploration and collection |
| Multiple rules | Level plus item | A compound gate |
A rule should normally combine conditions with AND: the player must satisfy every listed requirement. Within one alternative group, use OR when several paths should work.
UNLOCKS = {
"forest": {"level": 1},
"caves": {"level": 5, "requires": ["forest"]},
"boss_gate": {
"level": 10,
"requires": ["caves"],
"items": ["silver_key"],
},
}
def is_unlocked(name, player):
rule = UNLOCKS[name]
if player["level"] < rule.get("level", 1):
return False
if any(
requirement not in player["completed"]
for requirement in rule.get("requires", [])
):
return False
return all(
item in player["items"]
for item in rule.get("items", [])
)
player = {
"level": 6,
"completed": {"forest"},
"items": set(),
}
print(is_unlocked("caves", player)) # True
print(is_unlocked("boss_gate", player)) # FalseThe player can enter the caves because the level and completion conditions pass. The boss gate remains closed because the player is below level 10, has not completed the caves, and lacks the key.
Design Gates That Guide, Not Punish
A gate works well when its purpose is clear and the player can make progress toward it. Show the missing condition in the interface:
- “Reach level 10.”
- “Complete the Caves.”
- “Find the Silver Key.”
Avoid requiring a specific item when several equivalent actions could satisfy the same goal. For example, a locked door might accept a key, a high lockpicking skill, or a quest-based opening. This preserves direction without forcing one narrow solution.
Do not use level gates to hide content that the player could safely explore earlier. If a low-level player can enter an area but faces danger, communicate that danger rather than silently blocking the entrance.
Validate Dependencies
Prerequisites form a dependency graph. A content node points to the content that must come first.
Validate the graph during development. A missing prerequisite name should be an error, not an automatic unlock. Also detect cycles such as A requiring B while B requires A; such content can never become available.
Common errors include checking only the level and forgetting item or completion rules, using inconsistent identifiers, and permanently locking content after a player abandons a quest. Store stable IDs in save data, then resolve display names separately.
Exercise
A dungeon requires level 8, completion of mine, and either fire_key or ice_key. Should the condition use AND or OR for the keys?
Show answer
Use AND between the level and mine conditions, but OR between the two key alternatives. The player must meet the first two requirements and possess at least one key.