How to set up big tables?
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.
2 | number = number + change |
...Let me know what you think.
What I'm doing at the moment is:
03 | local UserId_list = { } |
05 | function _M.player_info(player) |
06 | local key = tostring ( "player_" .. player.UserId) |
08 | if UserId_list [ key ] then |
09 | return UserId_list [ key ] |
12 | local rss_meetatable = { |
20 | UserId_list [ key ] = rss_meetatable |
21 | return UserId_list [ key ] |
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 :)