Module 7 · Tables and Luau types
Dictionaries: values with named keys
Store related configuration under descriptive keys.
What you will learn
- Create a dictionary
- Read a value through a named key
- dictionary
- A table used to map keys to values.
- key
- A value used to look up another table value.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Coin Quest configuration is clearer as coinConfig.points than as an unexplained numeric position.
The mental model
A dictionary maps a key to a value. Dot syntax is concise for identifier-shaped string keys; brackets handle dynamic or non-identifier keys.
Keys describe roles, so dictionary order is not the main meaning.
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 “opening and closing braces”: it creates a table value around its entries.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
. is read as “dot”: it accesses a named property or table field.
A tiny example
--!strictlocal coinConfig = { points = 10, respawnSeconds = 8, isEnabled = true,}print(coinConfig.points, coinConfig.isEnabled)Line by line
- 3
The table groups related configuration.
- 4
points is a named key mapped to a number.
- 5
The unit appears in respawnSeconds.
- 6
isEnabled holds a boolean setting.
- 9
Dot syntax reads two named fields.
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 table groups related configuration.
Line 4: points is a named key mapped to a number.
Line 5: The unit appears in respawnSeconds.
Line 6: isEnabled holds a boolean setting.
Line 9: Dot syntax reads two named fields.
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: Every configuration value has a descriptive key and expected type.
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 expression reads the respawn delay?
Try it
Mark each step after you have tried it.
Common mistake
print(coinConfig[1])This dictionary was not built as an ordered array, so numeric position 1 has no meaning. Read a named key.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Dictionaries map keys to values.
- Named keys communicate roles.
- Dot and bracket lookups serve different key forms.
Next: Next, you will safely add, find, and remove array values.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.