Tables & Collections
In Lau, we use the {} symbols to create Tables. These are the most powerful part of the language, allowing you to store lists of items or complex data structures.
Simple Lists (Arrays)
Section titled “Simple Lists (Arrays)”A list is a collection of items stored in a specific order.
Basic Usage
Section titled “Basic Usage”To get the total number of items in a list, use the # (Length) operator.
lau-compiler.exe
varol mySeeds = {"Wheat", "Potato", "Tomato"}
print("Total Seeds: " + #mySeeds)print("First Seed: " + mySeeds[1])OUTPUT:
Total Seeds: 3
First Seed: Wheat
Dictionaries (Key-Value)
Section titled “Dictionaries (Key-Value)”Sometimes you want to store data by name instead of by number. This is called a Dictionary. This is perfect for storing Drone settings or player stats.
lau-compiler.exe
varol droneSettings = { autoBuy = true, autoSell = true, nickname = "FarmBot-9000"}
-- You can access data using a dotprint(droneSettings.nickname)OUTPUT:
FarmBot-9000
varol farmStats = { cropsHarvested = 100 }
-- Update the valuefarmStats.cropsHarvested += 1
-- You can also use square bracketsfarmStats["cropsHarvested"] = 200Iterating Tables
Section titled “Iterating Tables”The most common use for tables is looping through them to perform actions on every item. As learned in the Logic & Loops section, we use inpairs for this.
lau-compiler.exe
varol inventory = {"Apple", "Banana"}
for i, itemName inpairs(inventory) do print("Checking slot " + i + ": " + itemName)endOUTPUT:
Checking slot 1: Apple
Checking slot 2: Banana
System Limits
Section titled “System Limits”To ensure game performance, the Lau engine enforces the following limits on table data:
- Maximum Elements: A single table can hold up to 5,000 elements, although it may be hard to reach this as max character limit is 5,000 also.
- Persistent Data: Tables saved using the
data.module count toward your cloud storage limit.