I have dictionary, which use arrays for keys. As I know, {3, 5} == {3, 5} won’t be true bc this’s 2 diffirent tables, and due to this I have question - how I can replace Value in this situation, because writing with identical table should create new key-value pair?
local Dictionary = {
[{3,5}] = "Flame"
}
Dictionary[{3,5}] = "Star"
print(Dictionary[{3,5}]) --output is nil, because there's again new table
local function IndexTableKeyedTable(Table, ...)
local Arguments = {...}
for Key, Value1 in pairs(Table) do
if type(Key) ~= "table" then continue end --Ignore non-table keys.
for Index, Value2 in ipairs(Key) do
if Value2 ~= Arguments[Index] then break end
if Index == #Key then return Value1 end
end
end
end
local Table = {
[{3, 5}] = "Flame",
[{4, 7}] = "Star",
[{1, 1}] = "Flame",
[{8, 1}] = "Flame"
}
local Value = IndexTableKeyedTable(Table, 4, 7)
print(Value) --Star
You could define a custom function (like in the above) for querying tables with table indices.