🔧 MAKING YOUR OWN FUNCTIONS
lua
CopyEdit
function sayHello()
print("Hello, world!")
end
sayHello() -- Call it
Output:
CopyEdit
Hello, world!
🧠 function is how you define it
🧠 sayHello() is how you run it
You can pass values into a function:
lua
CopyEdit
function greet(name)
print("Hi, " .. name .. "!")
end
greet("Alex")
greet("Player1")
Output:
CopyEdit
Hi, Alex!
Hi, Player1!
You can make a function give you a result back:
lua
CopyEdit
function add(a, b)
return a + b
end
local result = add(5, 3)
print("The answer is", result)
Output:
csharp
CopyEdit
The answer is 8