Originally Posted by diiverr
Something looked odd in the function I posted, so I tried this as well:
Code:
function DiivSkins_hbar1Update()
if not (DiivSkinSettings) then
DiivSkinSettings = {}
DiivSkinSettings.hbar1 = 2
elseif(DiivSkinSettings.hbar1 == 1) then
DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.9023437, 0.984375);
elseif(DiivSkinSettings.hbar1 == 2) then
DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.8203125, 0.9023437);
etc.
still produces a nil error.
edit: sorry, still produces a nil error when called after the VARIABLES_LOADED event fires. (rather than from the slider <OnValueChanged>, where it works)
|
As mentioned above, stuff happens before this function ever gets called. Notably OnValueChanged.
In OnValueChanged it's trying:
DiivSkinSettings.hbar1 = this:GetValue()
when DiivSkinSettings doesn't exist. This is one reason I avoid putting time-dependent stuff into the xml. You can write an entire mod in the xml portion but especially starting out it helps enormously to break things down into sequence.
Do this:
1. Move this to the top of your mod:
DiivSkinSettings = {}
DiivSkinSettings.hbar1 = 2; -- whatever you want for default
DiivSkinLoaded = false
for a lot of bars, you can do:
DiivSKinSettings = { hbar1=2, hbar2=2, hbar3=2, hbar4=2 }
and it's the equivalent of:
DiivSkinSettings = {}
DiivSKinSettings.hbar1 = 2
DiivSKinSettings.hbar2 = 2
DiivSKinSettings.hbar3 = 2
DiivSKinSettings.hbar4 = 2
2. In the VARIABLES_LOADED event
DiivSkinLoaded = true
DiivSkins_hbar1Slideretcforgotname:SetValue(DiivSkinSettings.hbar1)
DiivSkins_hbar1Update()
3. In the OnValueChanged:
<OnValueChanged>
if DiivSkinLoaded then
DiivSkinSettings.hbar1 = this:GetValue();
DiivSkins_hbar1Update();
end
</OnValueChanged>
In the update function, remove the if not DiivSkinSettings bit.