Functions & Modules
Functions allow you to group code into a single command that can be used repeatedly. Modules allow you to share that code across different script files.
Defining Functions (func)
Section titled “Defining Functions (func)”A function is defined using the func keyword. You can pass information into them (parameters) and get information back (return).
lau-compiler.exe
func calculatePrice(price, amount) return price * amountend
varol order1 = calculatePrice(15, 10)varol order2 = calculatePrice(20, 20)
print("Total: " + order1)print("Total: " + order2)OUTPUT:
Total: 150
Total: 400
Multiple Return Values
Section titled “Multiple Return Values”Lau functions can return more than one piece of data at the same time.
lau-compiler.exe
func dronePosition() return drone.getPositionX(), drone.getPositionZ()end
varol hX, hZ = dronePosition()print("X: " + hX + ", Z: " + hZ)OUTPUT:
X: 0, Z: 0
Modules and req()
Section titled “Modules and req()”As your drone script grows, your code will become complex and long. The Module System helps you stay organized by splitting code into multiple files.
File Types
Section titled “File Types”.lau(Main Script): The primary script that controls the Drone..laum(Module): A helper script. It doesn’t run on its own; it must be called by a.laufile.
How to use Modules
Section titled “How to use Modules”Step 1: Create a module (math_tools.laum)
varol maths = {}
maths.add = func(a, b) return a + bend
return maths -- Essential!Step 2: Call it from your main script
varol myTools = req("math_tools.laum")print(myTools.add(10, 5)) -- Result: 15Events & Connections
Section titled “Events & Connections”Events are triggered when something happens in the game (like a player chatting or the weather changing). You use :connect() to tell your script to react.
| Method | Description |
|---|---|
:connect() | Runs the function every time the event happens. |
:once() | Runs the function only the first time the event happens. |
:disconnect() | Stops the script from listening to the event. |
lau-compiler.exe
-- This runs every time the player types in chatplayer.chatted:connect(func(msg) print("Player said: " + msg)end)
print("[Listening for Chat...]")OUTPUT:
[Listening for Chat...]
Of Course it cant say what i said!! there is no chat on here silly!!