Tables
A table groups values together. Create one with {}.
local labels = { "FPS", "Position", "Biome" }
lh.drawln(labels[1]) -- Output: FPSlh.drawln(labels[3]) -- Output: Biome
labels[2] = "Coordinates"List indices start at 1, not 0. Reading a missing entry gives nil.
Use ipairs() to visit a list in order, as shown in Loops.
Named fields
Section titled “Named fields”Tables can also hold values under named keys:
local settings = { title = "My HUD", scale = 2, visible = true,}
lh.drawln(settings.title) -- Output: My HUDsettings.scale = 3settings.title is short for settings["title"]. Use brackets when the key is stored in a variable:
local settings = { title = "My HUD" }local key = "title"lh.drawln(settings[key]) -- Output: My HUDsettings.key would look for a field literally named key instead.
Set a field to nil to remove it. false keeps the field with a false value.
List length and gaps
Section titled “List length and gaps”#list gives the length of a list with consecutive indices from 1:
local labels = { "FPS", "Position" }table.insert(labels, "Biome") -- Append an entry.lh.drawln(#labels) -- Output: 3
table.remove(labels, 2) -- Remove Position and shift later entries down.lh.drawln(labels[2]) -- Output: BiomeNested tables
Section titled “Nested tables”A table can contain other tables:
local hud = { position = { x = 10, y = 20 }, labels = { "FPS", "Biome" },}
lh.drawln(hud.position.x) -- Output: 10lh.drawln(hud.labels[1]) -- Output: FPSSharing a table
Section titled “Sharing a table”Assigning a table to another variable does not copy its contents. Both variables refer to the same table:
local settings = { scale = 1 }local other = settingsother.scale = 2
lh.drawln(settings.scale) -- Output: 2lh.drawln(settings == other) -- Output: truelh.drawln(settings == { scale = 2 }) -- Output: falseTwo separately created tables are different even when their contents match.