Skip to content

Logic & Control

Structures teach your drone how to think. They allow your scripts to react to the environment and repeat tasks automatically.


These are code blocks that will run if a certain condition is true.

  • if : Run this block if the condition is true.
  • elseif : If the above condition is false, check a new condition.
  • else : Run this block if no conditions match (otherwise).
  • then/end : Used to indicate the start and end of the condition.

The if statement evaluates a condition. If the condition is true, the code block executes. You can chain multiple checks using elseif and provide a fallback with else.

lau-compiler.exe
varol energy = 50
if energy > 80 then
print("Energy is full!")
elseif energy > 20 then
print("Energy is normal.")
else
print("WARNING: Energy is critical!")
end
OUTPUT:
Energy is normal.

Loops are essential for covering large farm plots without writing hundreds of lines of code.

Use this when you know exactly how many times you want to repeat an action.

Repeats within a specific number range. The third number (step) is optional.

lau-compiler.exe
-- Format: for variable = start, end do
for i = 1, 3 do
print("Moving to Tile: " + i)
end
OUTPUT:
Moving to Tile: 1 Moving to Tile: 2 Moving to Tile: 3

The while loop runs as long as the condition remains True.

lau-compiler.exe
varol hasLooped = false
while hasLooped == false do
--[[
Script will continue repeating until this
variable is met, you can do `while true do` to
form an infinte loop which continues forever
]]
print("Status: Hasn't looped")
hasLooped = true -- Condition met
end
print("Status: It Looped!")
OUTPUT:
Status: Hasn't looped Status: It Looped!

LAU uses a custom keyword inpairs to loop through lists (tables). This is perfect for checking inventory or planting a list of seeds.

lau-compiler.exe
varol seedList = {"Lemon", "Cacao", "Lotus"}
for index, seedName inpairs(seedList) do
print("Slot " + index + ": " + seedName)
end
OUTPUT:
Slot 1: Lemon Slot 2: Cacao Slot 3: Lotus

LAU uses uppercase keywords for logical operations.

OperatorDescriptionLogic
ANDConjunctionTrue if both conditions are true.
ORDisjunctionTrue if at least one condition is true.
NOTNegationReverses the value (True becomes False).

The NOT operator is perfect for checking if a drone is not doing something, or if a variable is empty.

lau-compiler.exe
varol isLocked = false
-- Use NOT to check if the condition is FALSE
if NOT isLocked then
print("Status: Drone is ready to move!")
end
OUTPUT:
Status: Drone is ready to move!

The OR operator is a powerful way to handle empty (null) data. It picks the first “True” value it finds.

lau-compiler.exe
varol savedName = null
varol displayName = savedName OR "Guest"
print("User: " + displayName)
OUTPUT:
User: Guest

Commands that allow you to change the flow of the loop based on the current iteration.

  • continue : Immediately ends the current iteration of the loop and jumps to the next one. (Does not run the code below it for that iteration).
  • break : Stops the loop completely and exits the loop.
-- Loop that only prints odd numbers and stops at 7
for i = 1, 10 do
if i % 2 == 0 then
continue -- Skip even numbers, go to the next one
end
if i == 7 then
break -- Finish the loop completely when 7 is reached
end
print(i)
end

Scope is the boundary that determines where a variable lives and where it dies. When a block ends, its local values are cleared from memory unless a nested function still captures them as upvalues.

  • Global Variable: Defined at the outermost level of the code. Accessible from anywhere (even inside functions).
  • Local Variable: Defined INSIDE an if, for, or func block. The variable is deleted when that block ends with end.
varol outside = "I am everywhere" -- Global
if true then
varol inside = "I am only here" -- Local
print(outside) -- Works
end
print(inside) -- ERROR! The 'inside' variable was deleted when the if block ended.

When a nested function still needs a local value, that value stays alive as an upvalue. This lets the runtime release unused block memory sooner while keeping captured values available.

func makePrinter()
varol text = "Hello from inside"
func printText()
print(text) -- text stays alive because this function captures it
end
return printText
end

The back-end reader of the Lau language is designed to perceive code line by line. This results in a very important rule:

  • Single-Line Restriction: If you write an if or for block on a single line without moving to a new line, the system only allows you to perform a SINGLE operation.
  • Multi-Operation: If you want to perform multiple operations when a condition is met, you MUST press ‘Enter’ and code on new lines.
-- CORRECT (Single line can be used for a single operation)
if speed > 100 then print("Slow down!") end
-- ERROR! (Two operations cannot be performed on a single line)
if speed > 100 then print("Slow down!") speed = 50 end
-- CORRECT (You must move to a new line for multiple operations)
if speed > 100 then
print("Slow down!")
speed = 50
end