On one script:
local Superclass = require(script.Parent.Parent:WaitForChild("TreeSuperclass"))
local TreeUtility = {}
TreeUtility.__index = TreeUtility
setmetatable(TreeUtility, Superclass)
function TreeUtility.Create()
local Tree = Superclass.Create()
setmetatable(Tree, TreeUtility)
Tree.Name = script.Name
return Tree
end
Tree.Create():Sapling()
return TreeUtility
Basically this creates the metatable with all of its inherited superclass data-etc.
On the other script:
function Utility:Sapling()
for _, Tree in Region.Trees do
if (SaplingPosition - Tree.TrunkPosition).Magnitude < RandomObject:NextInteger(self.SaplingSparsity[1], self.SaplingSparsity[2]) then
print"too close to another tree!"
return false
end
end
print"worked"
table.insert(ActiveTrees, self)
end
Trees are deleted from the ActiveTrees table once they die. However, if a tree is never added to the table, i.e no reference to it is ever established, will it get garbage collected? Or do I need to create some sort of custom destroy function for it?
Here’s the module script that actually creates the metatable if it’s important:
local Utility = {}
function Utility.Create()
local Superclass = {}
setmetatable(Superclass, Utility)
Superclass.Name = "Debug Tree"
return Superclass
end
return Utility
Does using ‘setmetatable’ give it a reference? Will I run into memory problems with custom cleanup code?