Module 3 · Expressions, operators, and text
Combining ideas with and, or, and not
Build readable boolean expressions from small game-state questions.
What you will learn
- Explain and, or, and not
- Trace a combined game-state expression
- logical operator
- An operator that combines or reverses boolean meaning.
- truth table
- A compact view of results for possible boolean inputs.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A door might require both a key and enough experience, while a tutorial hint may appear for a new player or anyone who asks for help.
The mental model
and is true only when both sides are truthy. or is true when at least one side is truthy. not reverses truthiness.
Name intermediate booleans when a sentence becomes difficult to read; the names preserve the game 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.
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.
= 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 levelHighEnough = falselocal canOpenDoor = hasKey and levelHighEnoughlocal showHint = not canOpenDoorprint(canOpenDoor, showHint)Line by line
- 3
The player has the required key.
- 4
The level requirement is not met.
- 5
and requires both facts to be true.
- 6
not reverses the false result for the hint state.
- 8
Both decisions are visible in Output.
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 player has the required key.
Line 4: The level requirement is not met.
Line 5: and requires both facts to be true.
Line 6: not reverses the false result for the hint state.
Line 8: Both decisions are visible in Output.
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 explain each result as a plain-language game rule.
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 is showHint in this state?
Try it
Mark each step after you have tried it.
Common mistake
local canOpenDoor = hasKey or levelHighEnoughor allows either requirement to be sufficient. If the design requires both, use and.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- and requires both sides.
- or accepts at least one side.
- not reverses truthiness.
Next: Next, you will combine numeric and text values into readable messages.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.