Hello Guys!
So I’m trying to make a custom UI class where recursion happens when calling the same function in a table like Roact.
Here is my module code
local module = {}
local GuiTypes = {
Frame = "Frame",
TextLabel = "TextLabel"
}
function createScreen(name, uiType, parent, tree)
local Gui = Instance.new(uiType)
Gui.Name = name
if parent then
Gui.Parent = parent
end
if tree then
if tree.Gui then
print("Tree: ", tree)
tree.Gui.Parent = Gui
end
end
return Gui
end
function module:MountElement(name, parent, tree)
createScreen(name, "ScreenGui", parent, tree)
end
function checkElement(Element)
if type(Element) == "table" then
return Element
end
end
function module:CreateUI(name: string, uiType: string, Element)
local Gui = createScreen(name, uiType)
local Property = {}
if type(Element) == "table" then
for i, v in pairs(Element) do
Property[i] = v
end
end
print("Property:", Property)
if Property and type(Property) == "table" then
for Name, element in pairs(Property) do
if element.Gui then
if element.Element then
local Mounted = checkElement(element.Element)
createScreen(Name, element.UIType, Gui, Mounted)
else
createScreen(Name, element.UIType, Gui)
end
end
end
end
return {
Gui = Gui,
UIType = uiType,
Element = Element
}
end
return module
Here is where the error occurs:
local player = game.Players.LocalPlayer
local UIClass = require(game.ReplicatedStorage.UiClass)
local Element = UIClass:CreateUI("Hello", "Frame", {
Recusive1 = UIClass:CreateUI("UAF", "Frame", {
-- recursion stops at recursive 1
Recursive2 = UIClass:CreateUI("2", "Frame", {
-- it doesn't work here
})
}),
})
UIClass:MountElement("Ulric", player.PlayerGui, Element)
any help is appreciated!