Overview
This lecture covers the basics of math operations, parameters, arguments, and return statements in Roblox scripting, emphasizing how they interact inside functions.
Math Operations in Roblox Scripting
- Basic math operations in scripts include addition (+), subtraction (-), multiplication (*), and division (/).
- Variables can be used to store the result of a math operation (e.g.,
local addition = 2 + 2).
- The
print() function outputs variable values to the Output window in Roblox Studio.*
Functions, Parameters, and Arguments
- A function is created using
local function FunctionName() syntax.
- Parameters are named variables inside function parentheses that accept values when the function is called.
- Arguments are the actual values passed to a function when it's called, matching the order of parameters.
- Functions with parameters can perform calculations on passed values and produce different results depending on the arguments.
Using Multiple Function Calls and Parameters
- Functions can be called multiple times with different arguments to produce varying results.
- Parameters can accept different data types, but calculations must be valid for those types (e.g., number + number).
Return Statements
- A return statement (
return variable) sends a value from within a function back to where the function was called.
- The result of a function can be stored in a variable and used elsewhere after calling the function.
- Use
print() outside the function to display the returned value.
Key Terms & Definitions
- Variable — A named location in memory for storing a value.
- Function — A reusable block of code that performs a specific task.
- Parameter — A named input in a function definition for receiving values.
- Argument — A value provided to a function parameter during a function call.
- Return Statement — A command in a function that sends a value back to the caller.
Action Items / Next Steps
- Create your own functions for subtraction, multiplication, and division.
- Experiment by adding more parameters to your functions.
- Save your work regularly using File > Save to File or by pressing Ctrl+S.