I’ve created a form to choose the settings: These settings are automatically saved in a file from the game client in this form:
["Setting"] = { ["track"] = "Spell Reflect", ["duration"] = { ["minimum"] = { ["enabled"] = 1, ["value"] = 3, }, ["maximum"] = { }, }, ["stack"] = { ["minimum"] = { }, ["maximum"] = { ["enabled"] = 1, ["value"] = 4, }, }, }
To save the settings in this form I used this function:
function UnitScan\_onAdvancedOptionClose() if not (db["duration"]) then db["duration"] = {} db["duration"]["minimum"] = {} db["duration"]["maximum"] = {} end db["duration"]["minimum"].enabled = minduration.cbutton:GetChecked() db["duration"]["minimum"].value = tonumber(minduration.ebox:GetText()) db["duration"]["maximum"].enabled = maxduration.cbutton:GetChecked() db["duration"]["maximum"].value = tonumber(maxduration.ebox:GetText()) if not (db["stack"]) then db["stack"] = {} db["stack"]["minimum"] = {} db["stack"]["maximum"] = {} end db["stack"]["minimum"].enabled = minstack.cbutton:GetChecked() db["stack"]["minimum"].value = tonumber(minstack.ebox:GetText()) db["stack"]["maximum"].enabled = maxstack.cbutton:GetChecked() db["stack"]["maximum"].value = tonumber(maxstack.ebox:GetText()) end
Where
- db = The “Setting” table
- GetChecked() = Returns whether the check button is checked
- GetText() = Returns the edit box’s text contents
Could you help me to make the code less repetitive and more elegant?