Hey guys, im making a database and I need to log key values such as playerID and playerName to a single value that links to the playerData for my social media game.
I would also like to use this for my products, to link productID and productNAme to a single productData value.
These exsist in languages like Java where you are able to build hashmaps that allow you to do things like this
You an create a sort of hashmap by creating a table and using indices with any type. Because tables are mutable, as long as you are referencing the same table both times, the change will be present under both indices
local productData = {}
local hash = {}
hash[userId] = productData -- equivalent of hash.put(userId, post)
hash[playerName] = productData
productData.exampleEntry = true
print(hash[userId].exampleEntry) --> true; equivalent of hash.get(userId).exampleEntry
print(hash[playerName].exampleEntry) --> true
-- would also work like so:
hash[userId].exampleEntry = true
print(hash[playerName].exampleEntry) --> true
print(productData.exampleEntry) --> true
hash[userId] = nil -- equivalent of hash.remove(userId)
table.clear(hash) -- equivalent of hash.clear()
-- to iterate over each entry in your hash,
for key, value in hash do
print(key, value)
end