Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I automate add things into a table ?

Asked by 4 years ago
Edited 4 years ago
local OriginalTable = {Coins = 0, Diamonds = 0,}
local UpdatedTable = {Coins = 0, Diamonds = 0, Table = {Table2 = {Table3 = {Table4 = {Table5 = {Alice = 0}, Asd = {}}}}}}

I want Original Table to have things UpdatedTable has

but is there a way I can do something like getdescendants and add them?

I know you can just add a table by doing OriginalTable['Table'] = UpdatedTable.Table but

what if I wanted to add something inside that table

for example

UpdatedTable = {Table = {NewTable = {}, AnotherTableUpdate = {} }}

so I needed Something like :GetDescendants

0
Each table could have a list of Children; GetDescendants could then recursively explore the Children. I am unsure how this would benefit you - what are you doing with these updated tables? You would probably benefit more from having a list of updates for a table (starting with the original), rather than trying to put updates inside of each other. chess123mate 5873 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You could have a loop running in the background in a coroutine, looping through updatedTable. run type(v), and check if type(v) == "table" or not. If it is a table, loop through v, check if there's tables, repeat. If type(v) ~= "table" then add it to originalTable.

If you need further clarification then please comment.
If this solution worked for you, please mark as correct!

0
I wouldn't recommend running anything in the background (just have a function that runs on request), but the rest of your idea sounds like a way of comparing two tables recursively (which could be good). chess123mate 5873 — 4y
Ad

Answer this question