iPollo Posted March 10, 2020 Share Posted March 10, 2020 (edited) Hello everyone, I recently discovered that it is possible to place tables within tables, this would have saved me a lot of work a week ago ; -; but anyway. Currently, to save the items contained in the player's inventory I have a copy of unique tables on each side (server / client) and every time there is an update, I need to move the value from one side to the other, but this seems to be very strange, i know that the fundamental principle of events is this, but I think I am not doing it in the best way. For example, I currently have the player_INV table, with 10 index for access, which I access like this: player_INV [1] player_INV [2] so on. Each of these variables stores the inventory item ID or 0 if not. for this I'm doing a looping and using getAccountData and setAccountData to save, my question is this: "1) set and get AccountData is good for this type of saving, or should I do a specific query on a table for this?" "2) As I have a copy on each side, I could just create a global table in serverSide, using the player as an index, and within each index of the player, I place another table that contains the inventory slot? Cause i would only need to exchange the information once, as I would only perform the reading and writing on serverSide, through clientSide, since everything is stored there." I'm still a novice, so who can explain to me if it's possible and if it's, why it's the best method, I'd be grateful Edited March 10, 2020 by iPollo Link to comment
Addlibs Posted March 11, 2020 Share Posted March 11, 2020 Using setAccountData you run the risk that items may get duplicated, since there is no protection against an item being listed in the account data of two accounts. Using a central MySQL (external) or sqlite (internal) database table, you could avoid this by having one list of items and who they belong to, rather than seperate lists per account. Link to comment
iPollo Posted March 11, 2020 Author Share Posted March 11, 2020 (edited) 2 hours ago, MrTasty said: Using setAccountData you run the risk that items may get duplicated, since there is no protection against an item being listed in the account data of two accounts. Using a central MySQL (external) or sqlite (internal) database table, you could avoid this by having one list of items and who they belong to, rather than seperate lists per account. Okay, and about the table, I found an example of a table structure (below) local items = { ['apple'] = {desc = 'A green apple', name = 'apple', objectid = '2134'} } how should i do, using tabel.insert, to add a new item without doing it manually in the table itself, leaving it like this: local items = { ['apple'] = {desc = 'A green apple', name = 'apple', objectid = '2134'} ['medkit'] = {desc = 'A healing item', name = 'Medic Kit', objectid = '431'} } I know that initially it is like this: table.insert(items, 'medkit', ...) what should I put to fill in the fields within the 'medkit' index Edited March 11, 2020 by iPollo Link to comment
Simple. Posted March 11, 2020 Share Posted March 11, 2020 2 hours ago, iPollo said: Okay, and about the table, I found an example of a table structure (below) local items = { ['apple'] = {desc = 'A green apple', name = 'apple', objectid = '2134'} } how should i do, using tabel.insert, to add a new item without doing it manually in the table itself, leaving it like this: local items = { ['apple'] = {desc = 'A green apple', name = 'apple', objectid = '2134'} ['medkit'] = {desc = 'A healing item', name = 'Medic Kit', objectid = '431'} } I know that initially it is like this: table.insert(items, 'medkit', ...) what should I put to fill in the fields within the 'medkit' index You can do it in two ways items['medkit'] = {desc = 'A healing item', name = 'Medic Kit', objectid = '431'} or table.insert(items, 'medkit', {desc = 'A healing item', name = 'Medic Kit', objectid = '431'}) 1 Link to comment
iPollo Posted March 11, 2020 Author Share Posted March 11, 2020 (edited) 1 hour ago, Simple. said: You can do it in two ways items['medkit'] = {desc = 'A healing item', name = 'Medic Kit', objectid = '431'} or table.insert(items, 'medkit', {desc = 'A healing item', name = 'Medic Kit', objectid = '431'}) Got it, but if i want to access a specific value, for example, the object id? how it should be? local objectid = items['medkit'].... Edited March 11, 2020 by iPollo Link to comment
Simple. Posted March 11, 2020 Share Posted March 11, 2020 1 hour ago, iPollo said: Got it, but if i want to access a specific value, for example, the object id? how it should be? local objectid = items['medkit'].... local objectid = items['medkit'].desc 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now