So my code is currently pretty unreadable to me. Currently what it does is simply set, read from, and initialize settings. What I currently dislike about my code is that it is basically unreadable, for me anyway.
For context, our options panel is laid out as follows:
> Column
> Setting Category Panels
> Container (holds list of items)
> List of settings & controllers
Because of these deep nests of options and the need to iterate through each and every one sort of recursively, it causes the need for deep nests of loops.
To reduce the number of indents, I’ve resorted to using guard clauses to skip to next iterations because I also need to check the class of each variable at each level of indent.
So because of this I run into 4 levels of
for i, name in ipairs(whatever:GetChildren()) do
if not name:IsA(class) then
continue
end
...
And because they all have similar names, it gets confusing, very quickly. It’s functional, and I’m satisfied with performance, but I really don’t know how I’d improve the readability of it.
Anyway, prepare your eyes:
for i, column in ipairs(container:GetChildren()) do
if not column:IsA('Frame') then
continue
end
for i2, settingCategory in ipairs(column:GetChildren()) do
if not settingCategory:IsA('Frame') then
continue
end
local foundSettingCategory = module._settingsInfo[settingCategory.Name]
if not foundSettingCategory then
return warn(`No setting category entry for {settingCategory}!`)
end
for i3, settingControlContainer in ipairs(settingCategory:WaitForChild('Container'):GetChildren()) do
if not settingControlContainer:IsA('Frame') then
continue
end
local thisInformation = foundSettingCategory[settingControlContainer.Name]
if not thisInformation then
warn(`No setting entry found for {settingControlContainer:GetFullName()}!`)
continue
end
Thanks in advance for any guidance. Let me know if you have any questions.