A table is like a container that can hold lots of data — numbers, strings, objects, even other tables.
lua
CopyEdit
local myTable = {"red", "blue", "green"}
print(myTable[1]) -- prints "red"
📌 Tables start at 1 (not 0 like some other languages!)
lua
CopyEdit
local playerStats = {
health = 100,
mana = 50,
name = "Knight"
}
print(playerStats["health"]) -- 100
print(playerStats.name) -- "Knight"
lua
CopyEdit
local team = {"npc1", "npc2"}
table.insert(team, "npc3") -- adds npc3 to the end
team[2] = "newNPC" -- changes npc2 to newNPC
print(team[2]) -- "newNPC"
lua
CopyEdit
table.remove(team, 1) -- removes the first item
| Use Case | Example Table |
|---|---|
| Team NPCs | teamRed = {"npc1", "npc2"} |
| Spawn Waves | waves = {{"npcA"}, {"npcA","npcB"}} |
| Unit Stats | {name="Swordsman", health=100, damage=15} |
| UI Buttons / Cost | {Swordsman=100, Archer=150} |