local t = {}
t.t2 = {}
--Or
local t = {}
local t2 = {}
External tables are two different tables, a nested table is a single table containing the information of both of your external tables. So it depends on what you’re trying to do. For example if you’re saving data you need a nested table(since you want to store all info at once instead of using multiple datastore keys). It also depends on the relation between said tables.
Also keep in mind that a table variable has the table reference not a copy of the table, so if you do:
local t2 = {}
local t = {}
t.t2 = t2
and then you do:
t2.Coins = 10 --example
the value of t.t2
will also change. That’s why sometimes we need to shallow copy or deep copy tables. A shallow copy is copying the table one layer deep(so tables within the table remain as references). A deep copy is a full copy of the old table using a recursive method. Deep copying is often used in algorithms of data manipulation where the inputs are tables and also when we use tables instead of objects for an object-related task. It’s a way to avoid destroying information.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.