The variable, DiivSkinSettings.hbar, is saved in my savedvariables, and it does save the textCoord's of whatever the slider was last on, but It only refreshes them after I open up that page of my configuration doohickey. Until that point, the full 12 slot bar is displayed. After the config page is opened and then closed, the correct "slot" confguration will persist.

The above code produces no errors, but has the mentioned issues. I tried just about everything I could think of to check for the value of the slider, but nothing worked. Almost every variant produced errors mostly pointing at the "DiivSkins_hbar1Update()" function. Either the reference in the slider XML was "referencing a nil value", or the lua broke alltogether, disabling all the other functions for buttons toggles and such that are present in the lua. This include trying to call the Update function from anywhere other than the <OnShow> in the slider XML. From there, its fine. Anywhere else, I get "an attempt to call a nil value" or it flat out tells me the function is broken.

I hope I explained that well enough. I'm sure I'm making some pretty elementary mistakes, but I feel like I'm getting close anyway.

On the value not chaning right away: A slider's OnValueChanged will get called BEFORE your variables are loaded. As part of a slider's initialization it will call OnValueChanged. This may be why its last state is not being saved initialially. I don't see a DiivSkins_hbar1Update() but I suspect it's assuming variables are loaded and they're not yet. (and in fact it'd be overwritten by this:GetValue())

How I handle sliders is this:
1. In the mod's initialization, after VARIABLES_LOADED, I slider:SetValue(last position)
2. In the slider's OnValueChanged() function, I check first if the mod is loaded, and if it is, then I assume the current position is valid and work with it from there.

When troubleshooting a sequence of events I'll often pepper my code with a lot of DEFAULT_CHAT_FRAME:AddMessage("In OnValueChange now") and stuff like the above will stand out right away.

Thank you much for the reply Gello, that was very helpful. I knew I had issues with my vairables, I just didn't know how or why. I was quite frankly astonished it worked as well as it did at first go.

I will have to try the chat frame mssg's. I thought maybe the "stock" XML frame was being rendered until the <OnShow> update worked its way into the mix, but I wasn't sure if it was that, or a variable value of 12 for some reason. That will be a good way to know for sure.

I was also worried about the way the update function read.

If yadayada then
elseif yadayada then
something yada

Seems logical that it should read more to the tune of

If yadayada then
something yada
elseif yadayada then
something yada

I thought for sure that was where "flags might have been thrown up," but I couldn't seem to get anything to work right there. Typically, my brain's idea of logic and lua's idea of logic seem to be at odds most of the time anyway.

[grumble]
While your post makes sense to me, I'm afraid I can't get the syntax correct. Heck, I can't even get the actual value to display in a CHAT_FRAME dump. I can display a message, but nothing productive.

Originally Posted by Gello

On the value not chaning right away: A slider's OnValueChanged will get called BEFORE your variables are loaded. As part of a slider's initialization it will call OnValueChanged. This may be why its last state is not being saved initialially. I don't see a DiivSkins_hbar1Update() but I suspect it's assuming variables are loaded and they're not yet. (and in fact it'd be overwritten by this:GetValue())

How I handle sliders is this:
1. In the mod's initialization, after VARIABLES_LOADED, I slider:SetValue(last position)
2. In the slider's OnValueChanged() function, I check first if the mod is loaded, and if it is, then I assume the current position is valid and work with it from there.

When troubleshooting a sequence of events I'll often pepper my code with a lot of DEFAULT_CHAT_FRAME:AddMessage("In OnValueChange now") and stuff like the above will stand out right away.

What I think is happening is that my savedvariable texture reference, while being saved, is not being called until the slider is visible. I verified this by changing the root textCoord's of the original xml frame, as this frame is not hidden. (I just did something wacky to get a distorted image displayed).

On start up, I get the base (distorted) XML texture. Once I open the slider page, then the frame's SetTexture reference from the slider value is recognized and employed, and all is well. This will persist until reload/relog. Then we start over. The variable is saved, but not displayed, until I access the slider. I don't even need to adjust it, just make it visible on screen by opening its page in my config UI. The moment the slider is displayed on screen, the texture for the frame in question is displayed, correctly, from the saved variable as well.

Could you maybe point me at an AddOn that initializes referencing a Slider Value? I couldn't seem to find one, but maybe looking at how its done might help me. My brain tells me the slider value isn't the problem, but that I'm just not actively displaying the data contained in the SavedVariable on initialization.

I would think just running the update function would accomplish this, but I can't for the life of me get that DiivSkins_hbar1Update() function (posted earlier) to fire from anywhere other than the <OnValueChanged> call of the slider xml.

It always returns a ...attempt to call global ... (a nil value) pertaining to itself if I try to call it from an OnEvent or an OnLoad.
[/grumble]

Thanks in advance for any assistance anyone might be able to give, and for patronizing the unedumaceted.

Setup your slider to change the savedVariable, and then call your textureUpdate function. You already have that so you are almost there...

Setup your textureUpdate function to check for the existence of the variable it needs. if the variable isn't there, then it needs to be created, which I assume you have elsewhere in your script, so we don't need to go over that. Once it has the varaible it needs, then change the texture. You have that, although the syntax is badly written, so you may want to fix that. I can assist if you need.

The final thing that needs to be done, which is your primary problem, is that you need to add a script section to your DiivSkins_Hbar1 frame. You see, the slider will NOT do anything until it gets shown. That means the config options have to be opened EVERY session in order for your texture to get updated. So you need to add the texture update to something that will be on screen every session. Since the frame mentioned above is the one with the texture you plan to change, it should have the update script in its OnEvent section. Do it like this:

Basically that means that whenever someone loads the game, and after the varaibles get loaded, the texture update function will get run, which checks to see what they have set for that variable (if at all, else it creates a default value) and then udpates the texture accordingly.

Hopefully this gets you where you are trying to go. As always, let me know if you need any assistance. Especially with that texture Update function, as it looks like you didn't format the if, else, and elseif's correctly...

function Recap_IdleFightSlider_OnValueChanged(arg1)
if recap_temp.Loaded and arg1 then
RecapIdleFightSlider_Text:SetText(arg1.." seconds");
recap.Opt.IdleFightTimer.value = arg1;
end
end

Try moving stuff out of the OnLoad/OnShow and into your VARIABLES_LOADED event. That way you're not dependent on when the UI gets around to loading up your UI during startup.

I would think just running the update function would accomplish this, but I can't for the life of me get that DiivSkins_hbar1Update() function (posted earlier) to fire from anywhere other than the <OnValueChanged> call of the slider xml.

Don't try fitting everything into the xml. In many cases it's better to manipulate stuff in your OnEvent handlers than the control's own event handlers.

his problem isn't the slider. The slider is doing what it needs to do. His problem is that when he changes the slider, it changes the texture, as intended (or it should) but if you log out, and back in, the texture will be at the default until he opens and updates the slider.

He simply needs an onload in his initial frame to get the variable when the player logs in. The slider only needs to change it if they plan on changing it, not change it on game-load.

On a side note, I could easily fix your issues as posted and post the updated code, but I prefer not to. The only way for a person to learn (or at least the way I learn best) is by breaking it, and fixing it yourself. So I will kinda nudge you in the right direction, and help you when you need it, but anything more than that might hurt your own learning process

That, save the check in the Update function itself for the variable, is a variation of what I have been trying, although I was calling for the Update function from elsewhere, typically in my normal OnEvent function. The net result of your suggestion, assuming I executed it properly) produced the same nil error as before regarding the Update function itself. I get this error at startup or reload, or, I assume, when VARIABLES_LOADED fires.

you did say:

... although the syntax is badly written, so you may want to fix that. I can assist if you need.

I think(?) Gello set me straight there. I hope I did that correctly. For the record, I will ALWAYS welcome help in that arena, or any other for that matter, so don't be shy, and thank you.

Gello,

I will definitely take a look at Recap, and see if that doesn't shed any light for me, thank you. From a cursory examination of what you posted here, there does seem to be some pretty fundamental structural differences in the way you coded it all. (I don't understand the "arg" notion either, but admittedly I haven't attempted to dissect them yet.)EDIT: Whoah, how have I missed this! (sorry, just got into game with recap, that looks to be a very slick little toy. )

RE:

Don't try fitting everything into the xml. In many cases it's better to manipulate stuff in your OnEvent handlers than the control's own event handlers.

I probably poorly worded that. When I said fire, I meant I have the line: DiivSkins_hbar1Update(); in my <OnValueChanged>, and that seems to be the only place it doesn't return a nil error when called.

The important bit, which should be stressed above all else, is that OnValueChanged will happen BEFORE variables are loaded. It's part of a slider's initialization when the game loads up.

Do you have DiivSkinSettings defined outside the functions above? Looking at it more closely I wonder that you don't get nil errors in the initial OnValueChanged.

If your mod looks like:

Code:

function OnLoad()
this:RegisterEvent("VARIABLES_LOADED")
end
function OnEvent()
if event=="VARIABLES_LOADED" then
DiivSkinSettings = {}
DiivSkins_hbar1Update();
end
end
Then in the xml:
<OnValueChanged>
DiivSkinSettings.hbar1 = this:GetValue();
DiivSkins_hbar1Update();
</OnValueChanged>

is going to be a mess. Because DiivSkinSettings is not defined yet. (OnValueChanged will get called BEFORE variables are loaded)

You can do this:

Code:

DiivSkinSettings = {}
function OnLoad()
this:RegisterEvent("VARIABLES_LOADED")
end
function OnEvent()
if event=="VARIABLES_LOADED" then
DiivSkins_hbar1Update();
end
end

By moving DiivSkinSettings = {} outside the functions, when the xml is loaded and it hits the Script file="whatever.lua", it will run the lua file and make DiivSkinSettings = {} before anything happens in your xml.

Or you can do

Code:

<OnValueChanged>
if DiivSkinSettings then
DiivSkinSettings.hbar1 = this:GetValue();
DiivSkins_hbar1Update();
end

Other stuff I notice:

Code:

<OnShow>
if (DiivSkinSettings.hbar1) then
this:SetValue(DiivSkinSettings.hbar1);
end
</OnShow>

If DiivSkinSettings isn't defined yet (ie, if before VARIABLES_LOADED), then this will give an error. It's trying to see if a value beneath an undefined table exists.

When checking if something exists, if it's a table then the elements above it must exist or it will give an error. the above should read:

Code:

<OnShow>
if DiivSkinSettings and DiivSkinSettings.hbar1 then
this:SetValue(DiivSkinSettings.hbar1);
end
</OnShow>

If DiivSkinSettings doesn't exist it will fail right away. If it exists it will see if hbar1 beneath it exists.

But again, realize that OnValueChanged() gets called BEFORE VARIABLES_LOADED. You may think OnValueChanged() is the result of someone moving the slider but it can (and is) also the UI setting the default value.

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.

As an aside, I assume you plan to create multiple bars, and therefore plan to make each one skinnable. Let me know if this is teh case, as I have simple code that can be plugged into the existing functions to make them work for ANY bar you want. Makes sense to use a single function for all your bars, and make that function work based on which bar is being passed to it. Smaller footprint = good

I have some real work to do now, but I will definitely be all over this later tonight.

Thanks so much for the help, both of you. Rest assured I'll report back when I have a chance to sit down with all this.

PS:
Yes, I will be adding multiple bars, as well as other elements. The end goal is to have configuration options for everything in my "kit" ( screenie ).

So, one of these widgets for each bar, horizontal and vertical, and probably a variation for the smaller elements, like a slider for each griffon that would toggle it between an assortment of images (lion, griffon, wyvern, right facing or left facing, etc.). At that point, it wouldn't be difficult (even for me) to break up the AddOn a bit into more of a "plugin" system, so users could only install the files that had the images they actually wanted to use if they wanted to keep it "lite". (We've already discussed that this won't have much of an impact on most systems, but "perception is reality." At the very least, this AddOn is pretty texture heavy, and busting it up into optional "expansions" would probably lighten the bandwidth load for Cairenn here).

I also want to ultimately include a "hide" checkbox, and a "lock" checkbox (to toggle moveability). I hadn't gotten far enough to sort how those variables would be saved yet either. I had thought originally the hide value at least could be a value outside the slider range, but now I'm not so sure. Regardless, the plan was to default all this crap to being checked "locked" and "hidden" so the user could selectively un-hide and manipulate elements as they set up their interface. Right now, they have that entire mess presented at first, and have to navigate within the restraints of a loooong MoveAnything scroll box to configure their set up. It's fairly unwieldy for even simply tweaking a layout in its presently released state. While I can't speak for all, I know I tend to "tweak" a lot.

The goal is to reduce MoveAnything! to an optional dependency, with a much shorter list for its MAPredefined frames file if the user opts to employ it. The purpose of this being mainly just so an individual could re-size an element if they desired. (I'm quite happy with MoveAnything's functionality for re-sizing, and don't see any reason to re-invent that particular wheel) All other functionality could be handled by DiivSkins. I think (with both your help) I'm getting much closer, and I can't thank you enough.

The possibilities start to get pretty broad, but its all the same basic principal. Ultimately, I'd like to think this could even "set a stage" for some actual artists to maybe have a go at doing some real tangible reskinning work on default elements, and still maintain configurability for the user. Now that would be exciting, much more so than my cut-and-paste hack job for a bunch of superfluous images on screen.

I was just trying to get this first bit working correctly first, and hopefully learn enough along the way that I wouldn't need to keep badgering gracious souls such as yourselves.
Much of what I detailed above I can now handle, but there's obviously a few "gaps" in my fledgling knowledge base just yet.

(I've already learned so much that I snikker at myself when I look at the currently released mod's code, and that's almost entirely just XML. Heck, I didn't even comment things very logically. )

OK, I think we're getting somewhere. I've gutted most of the original AddOn at this point. About the only thing left is the frames and functions we're discussing, and odds and ends relating to my funky options window.

Using the advice above, I'm mostly employing Beladona's code, with a few excepted suggestions by Gello, which did eliminate the odd error.

Some of the variables stuff seems redundant to me, and I will re-read your posts tomorrow with a fresher brain Gello. That said, the changes (additions) I made did eliminate all errors except for this one:

I get that whenever variables are loaded, or the slider is shown. Basically, the same "Update" function nil error as before.

The saved variable is saving correctly now and displaying the correct texture after VARIABLES_LOADED is triggered, and not displaying the original frame texture until an <OnShow> trigger as before.

Unfortunately, the slider is no longer working to dynamically update the texture in game. That is, it saves its variable, which is then displayed correctly the next time they are loaded, but nothing visually happens on screen when you adjust the slider. You need to reload to see the changes you have made. I can almost see where you are going with this however Beladona, so I'm more than willing to get it working if you are.

I'm getting tired, so I'll take a look at this again tomorrow with fresher eyes. I just wanted to give you both a status report.

EDIT:
Still haven't had coffee yet, but I will look at the variables some more today. The appear to be working fine in game, but something looks fishy with what I added to Beladona's code. Didn't you set up a local for the DiivSkinSettings Beladona? And then I added them as globals for some sort of validity check?

Sorry, I've been staring at this for so many hours trying to sort it through, I think its time to step away for a day and let my brain clear out all the crap I tried, so I can go back to working with bonafide code again. LOL.

Beladona, if you want to withhold your "simple code that can be plugged into the existing functions to make them work for ANY bar you want" for the time being and let me try to figure it out for myself, I won't mind at all. I think once I stop staring at this with one hand on the save button and the other on the reloadUI button and actually just read the code, It will probably make a lot more sense.

Of course, If you want to continue to write this AddOn for me, <blush> I'm not proud.
Thanks for all your help.

-- lua script --* removed the first few lines as it will mess up your config settings
* changed the load detection a little pending inclusion of your other bars
* added DiivSkinTextures[1] since you now support settings 1 through 12 on the slider

On a side note, your slider shouldn't be doing anything with the hbar1 setting until you actually open the config and start changing values. Based on that, you dont need to check for the setting before changing it. Just change it as I have it above, because by the time you actually even see this slider, you will already have run your onLoad for your bar, which makes sure the setting is there. It will ALWAYS be there by the time the slider is shown.