Hello folks, I am having a hard time using metatables.
How would I return a table that gets cloned when indexed??
Here’s my module
local Deepcopy= require(script.Parent.Parent.Utils.DeepCopy) --function that copies everything nested within the table
local SavedMaps = {}
SavedMaps.SmileyFace = {
{0,1,0,1,0},
{0,1,0,1,0},
{0,0,0,0,0},
{1,0,0,0,1},
{0,1,1,1,0},
}
SavedMaps.Dot = {
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
}
SavedMaps.Triangle = {
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,1,0},
{1,1,1,1,1},
{0,0,0,0,0},
}
--How would I do deepcopy????
return SavedMaps
So when I would call that table, it would return a copy of it
local Presets = require("Presets")
local Matrix = Presets.SmileyFace --> This is a copy of SmileyFace
The reason why I ask this is that lua’s tables are anonymous and the tables within will have its values changed if I didn’t clone which can cause bugs.