Module 6 · Functions and scope
Function parameters
Name inputs in a definition and supply argument values at each call.
What you will learn
- Distinguish parameters from arguments
- Choose meaningful parameter names
- parameter
- A local name for input inside a function definition.
- argument
- The value supplied by a particular call.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
One Coin Quest message function can describe different coin amounts when the changing value arrives as input.
The mental model
A parameter is the function's input name. An argument is the actual value a caller supplies.
Parameters exist only inside that function call, so name them for the role they play.
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.
end is read as “end”: it closes a block such as a decision, loop, or function.
A colon in a declaration, such as coins: number, introduces a type annotation: the kind of value that name is allowed to hold.
A tiny example
--!strictlocal function announceCoins(coinCount: number) print(`Coins collected: {coinCount}`)endannounceCoins(3)announceCoins(8)Line by line
- 3
coinCount is a numeric parameter.
- 4
The body formats the current call's input.
- 7
The first call supplies 3 as an argument.
- 8
The second call supplies a different argument.
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
Start with the statements outside function bodies. A function definition creates a callable value; its body runs when a call, event, or scheduled task reaches it.
Trace the arguments at each call and the branch or loop inside that call. Return to the caller when the function returns. For an event, use the action named in Try it to trigger the callback.
Line 3: coinCount is a numeric parameter.
Line 4: The body formats the current call's input.
Line 7: The first call supplies 3 as an argument.
Line 8: The second call supplies a different argument.
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: Each call maps its argument values to meaningful parameter names.
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 does the second call insert in its message?
Try it
Mark each step after you have tried it.
Common mistake
local function announceCoins(value)The generic name hides the input's role. coinCount: number communicates both meaning and intended type.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Parameters name function inputs.
- Arguments supply call-specific values.
- Meaningful names and types make the contract readable.
Next: Next, you will send a calculated value back to the caller.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.