🔧 MAKING YOUR OWN FUNCTIONS

🛠️ How to make a function

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


⚙️ Function with parameters (input)

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!


➕ Function that returns something

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