Module 2 · Values and variables
What a value is
Recognize string, number, boolean, and nil values before giving them names.
What you will learn
- Identify four foundational value types
- Separate a value from the name used to store it
- value
- A piece of data a program can store or use.
- nil
- The absence of a value.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Coin Quest needs to remember text such as a player name, a number of coins, whether the player is alive, and whether an item has been selected.
The mental model
A value is the data itself: "Ari", 25, true, or nil. A name such as coins can point to a value, but the name and value are not the same thing.
Strings hold text, numbers support arithmetic, booleans represent true or false, and nil represents no value.
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.
A tiny example
--!strictprint("Ari")print(25)print(true)print(nil)Line by line
- 3
Quoted Ari is a string value.
- 4
25 is a number value.
- 5
true is a boolean value and has no quotes.
- 6
nil means no value is present.
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: Quoted Ari is a string value.
Line 4: 25 is a number value.
Line 5: true is a boolean value and has no quotes.
Line 6: nil means no value is present.
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: Output contains text, a number, a boolean, and the word nil representing an absent value, in that order.
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
Which printed value can be used directly in arithmetic?
Try it
Mark each step after you have tried it.
Common mistake
print("true")Quotes turn true into the text "true". That string may look similar in Output, but it is not the boolean value used by conditions.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Values are data.
- Strings, numbers, booleans, and nil carry different meanings.
- A variable name is separate from its current value.
Next: Next, you will create local variables and change the values they store.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.