Logic & Control
Structures teach your drone how to think. They allow your scripts to react to the environment and repeat tasks automatically.
Decision Structures (if, elseif, else)
Section titled “Decision Structures (if, elseif, else)”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.
Syntax Example
Section titled “Syntax Example”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!")endLoops are essential for covering large farm plots without writing hundreds of lines of code.
1. Numerical Loops (for)
Section titled “1. Numerical Loops (for)”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.
-- Format: for variable = start, end dofor i = 1, 3 do print("Moving to Tile: " + i)end2. While Loops (while)
Section titled “2. While Loops (while)”The while loop runs as long as the condition remains True.
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 metend
print("Status: It Looped!")Iterating Collections (inpairs)
Section titled “Iterating Collections (inpairs)”LAU uses a custom keyword inpairs to loop through lists (tables). This is perfect for checking inventory or planting a list of seeds.
varol seedList = {"Lemon", "Cacao", "Lotus"}
for index, seedName inpairs(seedList) do print("Slot " + index + ": " + seedName)endLogic & Short-Circuiting
Section titled “Logic & Short-Circuiting”LAU uses uppercase keywords for logical operations.
| Operator | Description | Logic |
|---|---|---|
| AND | Conjunction | True if both conditions are true. |
| OR | Disjunction | True if at least one condition is true. |
| NOT | Negation | Reverses the value (True becomes False). |
Reversing Logic with NOT
Section titled “Reversing Logic with NOT”The NOT operator is perfect for checking if a drone is not doing something, or if a variable is empty.
varol isLocked = false
-- Use NOT to check if the condition is FALSEif NOT isLocked then print("Status: Drone is ready to move!")endDefault Values (Short-Circuit)
Section titled “Default Values (Short-Circuit)”The OR operator is a powerful way to handle empty (null) data. It picks the first “True” value it finds.
varol savedName = nullvarol displayName = savedName OR "Guest"
print("User: " + displayName)Loop Controls (Break & Continue)
Section titled “Loop Controls (Break & Continue)”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 7for 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)endScopes
Section titled “Scopes”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 and Local Variables
Section titled “Global and Local Variables”- Global Variable: Defined at the outermost level of the code. Accessible from anywhere (even inside functions).
- Local Variable: Defined INSIDE an
if,for, orfuncblock. The variable is deleted when that block ends withend.
varol outside = "I am everywhere" -- Global
if true then varol inside = "I am only here" -- Local print(outside) -- Worksend
print(inside) -- ERROR! The 'inside' variable was deleted when the if block ended.Upvalues
Section titled “Upvalues”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 printTextendSingle-Line Operations (Important)
Section titled “Single-Line Operations (Important)”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
iforforblock 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 = 50end