Module 4 · Making decisions
Combining conditions safely
Group conditions and name intermediate facts instead of hiding a rule in one dense line.
What you will learn
- Group a combined condition
- Extract readable intermediate booleans
- intermediate boolean
- A named true-or-false result used as part of a larger decision.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A locked door may require a key, a level, and an active round. Naming each rule makes failures easier to explain.
The mental model
Break a decision into facts with game-language names. Combine those facts only after each one is understandable.
Parentheses show intentional groups and reduce the chance that and/or precedence communicates a different rule.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
if is read as “if”: it starts a decision by evaluating a condition.
then is read as “then”: it marks the body that can run when the condition is truthy.
end is read as “end”: it closes a block such as a decision, loop, or function.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
A tiny example
--!strictlocal hasKey = truelocal playerLevel = 6local roundActive = truelocal meetsLevel = playerLevel >= 5local canOpen = hasKey and meetsLevel and roundActiveif canOpen then print("Door opened")endLine by line
- 3
The inventory fact is named.
- 4
The numeric state remains separate.
- 5
Round state is another fact.
- 6
The comparison receives a game-language name.
- 7
The final rule combines three booleans.
- 9
The branch reads like a plain question.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 3: The inventory fact is named.
Line 4: The numeric state remains separate.
Line 5: Round state is another fact.
Line 6: The comparison receives a game-language name.
Line 7: The final rule combines three booleans.
Line 9: The branch reads like a plain question.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: You can identify which named fact prevents the branch from running.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
What makes meetsLevel true?
Try it
Mark each step after you have tried it.
Common mistake
if hasKey and playerLevel >= 5 or roundActive thenThis can open when only roundActive is true. Named facts and explicit grouping force you to state whether the round is an alternative or a requirement.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Named facts keep conditions readable.
- Grouping preserves the intended rule.
- Changing one input at a time helps diagnosis.
Next: Next, you will use truthiness and early exits to reduce nesting.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.