Skip to content

Maps

In Lua, these structures are also called tables. These structures hold multiple data entries associated with a string index.

let emptyMap = map<number>{} // empty map initialization
let inventory = {
"bananas" = 2,
"apples" = 5,
"kiwis" = 10,
"pears" = 0,
"cherries" = 12, // trailing comma is optional!
}
Pewpew:Print(inventory["apples"]) // -> 5

You can also add new entries to the map.

let inventory = {
"bananas" = 2,
"apples" = 5,
"kiwis" = 10,
"pears" = 0,
"cherries" = 12,
}
inventory["watermelons"] = 10
Pewpew:Print(ToString(inventory))
/*
-> {
bananas: 2,
apples: 5,
kiwis: 10,
pears: 0,
cherries: 12,
watermelons: 10
}
*/