Hi guys,
I'd just like your advice of where to go with this, I think I'm on the right track but im not sure how to execute it... (I think I might be a bit out of my depth haha)
So I want to make a table which i can call from anywhere (so i'm putting it in a module script) which stores all of the values associated with a player. These will include currencies, experience data etc. I think I want to structure this as follows: (let me know if you'd do it differently
- Table where: index = "player_" ... player_UserId --(this will let me find the correct thing to edit late?) value = another table (see below) 2 (the value from part 1). Table where: index = file names (e.g. resources or data) value = another table (see below) 3 (the value from part 2, inside of ["resources"]). Table where: (theres another section similar to 2 to organise information, or...) index = currencies (e.g. gold, wood, stone etc.) value = the value associated with the index (this is the number to do maths on etc
I'm not sure if metatables are what I need because the table will just be storing numbers. Obviously these numbers will be changed as the player advances however, this addition/subtraction could just be done by getting the value out of the table e.g.
local number = --the number in the table
number = number + change
...Let me know what you think.
What I'm doing at the moment is:
local _M = {}
local UserId_list = {} -- a list of "player_" .. player.UserId
function _M.player_info(player) -- to be called when looking for the info table
local key = tostring("player_" .. player.UserId)
if UserId_list[key] then -- if there is already an entry in the table, return it
return UserId_list[key] --returns the table to be manipulated by another script and then it'll be sent back and stored again
else
local rss_meetatable = {
["gems"] = 0,
["gold"] = 0,
["food"] = 0,
["stone"] = 0,
["wood"] = 0,
["premiums"] = 0
} --a dictionary of resources and their starting value
UserId_list[key] = rss_meetatable -- creates a new key with the value set to the table above
return UserId_list[key] --returns the table to be manipulated by another script and then it'll be sent back and stored again
end
end
return _M
Is this script even close to doing what I'm tying to achieve? Is there a better way to do this?
Hopefully what I'm trying to do/explain has made sense and you can give me some pointers for what to read or what to do differently. Thank you!
If you have any questions please comment :)

2 comments
make sure to use setmetatable when making metatables.
So do you think using metatables is the way to do this? Should line 20 just say setmetatable(UserId_list[key], rss_meetatable)