Skip to content

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.


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 * amount
end
varol order1 = calculatePrice(15, 10)
varol order2 = calculatePrice(20, 20)
print("Total: " + order1)
print("Total: " + order2)
OUTPUT:
Total: 150 Total: 400

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

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.

  1. .lau (Main Script): The primary script that controls the Drone.
  2. .laum (Module): A helper script. It doesn’t run on its own; it must be called by a .lau file.

Step 1: Create a module (math_tools.laum)

varol maths = {}
maths.add = func(a, b)
return a + b
end
return maths -- Essential!

Step 2: Call it from your main script

varol myTools = req("math_tools.laum")
print(myTools.add(10, 5)) -- Result: 15

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.

MethodDescription
: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 chat
player.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!!