Thread Tools Display Modes
10-08-12, 09:16 PM   #1
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
slider variable saving and using

Lua Code:
  1. MyAddon = {};
  2.  MyAddon.panel = CreateFrame( "Frame", "MyAddonPanel", UIParent );
  3.  MyAddon.panel.name = "Smp";
  4.  InterfaceOptions_AddCategory(MyAddon.panel);
  5.  
  6.     --SLIDER
  7.     SlashCmdList["SMP"] = function() InterfaceOptionsFrame_OpenToCategory(MyAddon.panel) end
  8.     SLASH_SMP1 = "/smp"
  9.     local slider = CreateFrame("Slider","MyAddonSlider",MyAddon.panel,'OptionsSliderTemplate')
  10.     slider:SetPoint("CENTER",0,0)
  11.     getglobal(slider:GetName() .. 'Low'):SetText('25%');
  12.     getglobal(slider:GetName() .. 'High'):SetText('95%');
  13.     getglobal(slider:GetName() .. 'Text'):SetText('Health');
  14.     slider:SetMinMaxValues(25, 95)
  15.     slider:SetValue(70)
  16.     slider:SetValueStep(5)

how would i save the slider value after changing it (so its that value everytime i run wow)
and how would i find the value of the slider such as "slider.Value" etc.
  Reply With Quote
10-08-12, 10:17 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-09-12 at 11:05 PM.
  Reply With Quote
10-08-12, 10:56 PM   #3
Spawnova
A Warpwood Thunder Caller
 
Spawnova's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 96
Perfect thank you! =D
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » slider variable saving and using

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off