1. The
getglobal function was deprecated
years ago and should never be used by anyone for any reason. Use
_G[value] instead of
getglobal(value).
2. You use the
GetValue method on your slider to get the current value:
Code:
local value = slider:GetValue()
3. To save anything between sessions, you first need to define a saved variable for your addon. Add something like this to your TOC file:
Code:
## SavedVariables: MyAddonSetting
4. Then, you need to initialize the variable with a reasonable default setting:
Code:
MyAddon.panel:RegisterEvent("PLAYER_LOGIN")
MyAddon.panel:SetScript("OnEvent", function(self)
MyAddonSetting = MyAddonSetting or 65 -- Default to 65
end)
5. If you are only saving one setting, you can just use the variable directly:
Code:
## SavedVariables: MyAddonSliderValue
Code:
slider:SetScript("OnValueChanged", function(self)
local value = self:GetValue()
-- Save the value to your saved variable:
MyAddonSetting = value
-- Do whatever you want with the value here.
end)
6. If you want to save more than one setting, you should use a table:
Code:
## SavedVariables: MyAddonSettings
Code:
MyAddon.panel:RegisterEvent("PLAYER_LOGIN")
MyAddon.panel:SetScript("OnEvent", function(self)
MyAddonSettings = MyAddonSetting or {
slidervalue = 65,
othervalue = 12,
somevalue = "some string",
}
end)
slider:SetScript("OnValueChanged", function(self)
-- Get the slider's current value:
local value = self:GetValue()
-- Save the value to your saved variable:
MyAddonSettings.slidervalue = value
-- Do whatever you want with the value here.
end)
7. You should also add a
refresh function to your options panel to set the slider's value based on the saved setting:
Code:
MyAddon.panel.refresh = function()
slider:SetValue(MyAddonSettings.slidervalue)
end