The Lua code sample for tables on this page made a small error in how Lua dictionaries work, under the header of Tables > Dictionary Tables:
Sample:
local dictionary = {
val1 = "this",
val2 = "is"
}
print(dictionary.val1) -- Outputs 'this'
print(dictionary[val1]) -- Outputs 'this'
dictionary.val1 = nil -- Removes 'val1' from table
table.remove(dictionary, 1) -- Also removes 'val1' from table
dictionary["val3"] = "a dictionary" -- Overwrites 'val3' or sets new key-value pair
- This sample should use strings the first time bracket indexing was used.
-
table.remove
shouldn’t be used with dictionaries, as it can only be used on arrays.
Fixed:
local dictionary = {
val1 = "this",
val2 = "is"
}
print(dictionary.val1) -- Outputs 'this'
print(dictionary["val1"]) -- Outputs 'this'
dictionary.val1 = nil -- Removes 'val1' from table
dictionary["val3"] = "a dictionary" -- Overwrites 'val3' or sets new key-value pair
As a small nitpick, under the header of Conditional Statements > Ternary Operations:
Sample:
local max = (x>y and x) or y
- To my knowledge, parantheses don’t have to be used for Lua ternaries.
Fixed:
local max = x>y and x or y
The description above the sample also uses this style , (a and b) or c
, which should be changed to a and b or c
for continuity. It might also be useful to add that b
cannot be nil
either, as that counts as a non-truthy value.