Reply
Thread Tools Display Modes
Unread 06-08-05, 04:19 PM   #1
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
What am I missing?

OK. I am trying to make a configurable texture in game.

When I paint this frame:
Code:
<Frame name="DiivSkins_Hbar1" frameStrata="BACKGROUND" inherits="DiivSkins_hbarTemplate" parent="UIParent">
	<Size>
		<AbsDimension x="512" y="46"/>
	</Size>
	<Layers>
		<Layer level="ARTWORK">
			<Texture name="DiivSkins_hbar1Texture" file="Interface\AddOns\DiivSkins\Skins\diivskins_01">
				<TexCoords left="0.0019531" right="1.0" top="0.0" bottom="0.0898437"/>
			</Texture>
		</Layer>
	</Layers>
	<Anchors>
		<Anchor point="BOTTOM">
			<Offset>
				<AbsDimension x="215" y="550"/>
			</Offset>
		</Anchor>
	</Anchors>
</Frame>
I get this image: CLICKY


Now, I set up the following lua functions to alter that texture via a slider, and (hopefully) save it across sessions (most of this is hacked up and taken from the SquidMod code):
Code:
function DS_OnLoad()
	DiivSkins_LoadVariables();
	this:RegisterEvent("VARIABLES_LOADED");
end

function DiivSkins_LoadVariables()
	if not DiivSkinSettings then
		DiivSkinSettings = { };
	end
end

function DS_OnEvent()
	if event=="VARIABLES_LOADED" then
		if not DS_UsedBefore then
			-- do one-time stuff for first use here

			-- display the primary game menu without a keypress
			GameMenuFrame:Show();
			-- display an attatched text frame to this menu
			DS_Init:Show();

			-- Swap in the placeholder DiivSkins button on the game menu
			DS_GameMenuButton:Hide();
			DS_GameMenuButton_Init:Show();

			--register the variable as true, so the above never happens again.
			DS_UsedBefore = true
			
			--update my slider variables
		else if not (DiivSkinSettings) then
			DiivSkinSettings.hbar1 = {}
		end
	end
end

function DiivSkins_hbar1Update()
	if(DiivSkinsSettings) then
		elseif(DiivSkinSettings.hbar1 == 2) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.8984375, 0.9882812);
		elseif(DiivSkinSettings.hbar1 == 3) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.8085937, 0.8984375);
		elseif(DiivSkinSettings.hbar1 == 4) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.71875, 0.8085937);
		elseif(DiivSkinSettings.hbar1 == 5) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.6289062, 0.71875);
		elseif(DiivSkinSettings.hbar1 == 6) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.5390625, 0.6289062);
		elseif(DiivSkinSettings.hbar1 == 7) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.4492187, 0.5390625);
		elseif(DiivSkinSettings.hbar1 == 8) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.359375, 0.4492187);
		elseif(DiivSkinSettings.hbar1 == 9) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.2695312, 0.359375);
		elseif(DiivSkinSettings.hbar1 == 10) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.1796875, 0.2695312);
		elseif(DiivSkinSettings.hbar1 == 11) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.0898437, 0.1796875);
		elseif(DiivSkinSettings.hbar1 == 12) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.0, 0.0898437);
		end
	end
end
The OnLoad and OnEvent functions are called elsewhere in my XML, the "Update" function iis called from the slider XML:
Code:
<Slider name="DiivSkins_hbar1Slider" inherits="OptionsSliderTemplate">
	<Size>
		<AbsDimension x="160" y="17"/>
	</Size>
	<Anchors>
		<Anchor point="CENTER"/>
	</Anchors>
	<Scripts>
		<OnLoad>
			getglobal(this:GetName().."Text"):SetText("Horizontal Bar 1");
			getglobal(this:GetName().."High"):SetText("12 slots");
			getglobal(this:GetName().."Low"):SetText("2 slot");
			this:SetMinMaxValues(2, 12);
			this:SetValueStep(1);
		</OnLoad>
		<OnShow>
			if (DiivSkinSettings.hbar1) then
				this:SetValue(DiivSkinSettings.hbar1);
			end
		</OnShow>
		<OnValueChanged>
			DiivSkinSettings.hbar1 = this:GetValue();
			DiivSkins_hbar1Update();
		</OnValueChanged>
	</Scripts>
</Slider>


Now, here's where it gets odd. Here's another image: CLICKY (for reference)

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.

Any help?
diiverr is offline   Reply With Quote
Unread 06-08-05, 04:57 PM   #2
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 442
At a casual glance, a couple things throw up flags for me:

else if not (DiivSkinSettings) then
DiivSkinSettings.hbar1 = {}
end

If the above happens, then it will give an error. The above says if this table doesn't exist, then create a subtable under this non-existent table.

What you probably want is:

else if not (DiivSkinSettings) then
DiivSkinSettings = {}
DiivSkinSettings.hbar1 = (some default value)
end

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.
Gello is online now   Reply With Quote
Unread 06-08-05, 05:46 PM   #3
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
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.
diiverr is offline   Reply With Quote
Unread 06-08-05, 08:19 PM   #4
Sathanas
A Deviate Faerie Dragon
 
Sathanas's Avatar
AddOn Author - Click to view addons
Join Date: May 2005
Posts: 15
Originally Posted by Gello
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.
Hehe i thought i was the only one to do that.

My chat box looks funny when im working on something new.

thingy: 1
thatstuff: 5
things: Hunter
__________________
--Sathanas
Sathanas is offline   Reply With Quote
Unread 06-09-05, 06:51 AM   #5
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
[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.
diiverr is offline   Reply With Quote
Unread 06-09-05, 07:50 AM   #6
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
You need to do the following:

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:

<OnLoad>this:RegisterEvent("VARIABLES_LOADED");</OnLoad>
<OnEvent>if (event == "VARIABLES_LOADED") then TextureUpdateFunction(); end</OnEvent>

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...

Last edited by Beladona : 06-09-05 at 08:01 AM.
Beladona is offline   Reply With Quote
Unread 06-09-05, 07:58 AM   #7
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 442
It's not the best mod for an example of sliders, but Recap here has several sliders in RecapOptions.lua and RecapOptions.xml.

In the xml, I define the min/max/default of the slider in the slider's tag.

<Slider name="RecapIdleFightSlider" orientation="HORIZONTAL" enableMouse="true" minValue="5" maxValue="60" defaultValue="10" valueStep="1">

The scripts section only has tooltip bits and OnValueChanged:

<Scripts>
<OnEnter>
Recap_OnTooltip("IdleFightSlider");
</OnEnter>
<OnLeave>
GameTooltip:Hide();
</OnLeave>
<OnValueChanged>
Recap_IdleFightSlider_OnValueChanged(arg1);
</OnValueChanged>
</Scripts>


In/after the VARIABLES_LOADED event, I make recap_temp.Loaded=true and call Recap_InitializeOptions():

function Recap_InitializeOptions()
local chatname,chatid,i;
RecapAutoFadeSlider:SetValue(recap.Opt.AutoFadeTimer.value);
RecapIdleFightSlider:SetValue(recap.Opt.IdleFightTimer.value);
RecapMaxRowsSlider:SetValue(recap.Opt.MaxRows.value);
RecapMaxRankSlider:SetValue(recap.Opt.MaxRank.value);
etc
end

To set all the values from the last session.

Then OnValueChanged is very simple:

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.

Last edited by Gello : 06-09-05 at 08:01 AM.
Gello is online now   Reply With Quote
Unread 06-09-05, 08:03 AM   #8
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
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

Last edited by Beladona : 06-09-05 at 08:14 AM.
Beladona is offline   Reply With Quote
Unread 06-09-05, 08:37 AM   #9
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
Thank you for the replies. I know I'm clueless, but I sincerly appreciate your patience. I really am learning a lot.

Beladona,
I did as suggested... The update function now reads:
Code:
function DiivSkins_hbar1Update()

	if(DiivSkinsSettings) then
		if not (DiivSkinSettings) then
			DiivSkinSettings = {}
			DiivSkinSettings.hbar1 = 2
		end
		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);

		elseif(DiivSkinSettings.hbar1 == 3) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.7382812, 0.8203125);

		elseif(DiivSkinSettings.hbar1 == 4) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.65625, 0.7382812);

		elseif(DiivSkinSettings.hbar1 == 5) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.5742187, 0.65625);

		elseif(DiivSkinSettings.hbar1 == 6) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.4921875, 0.5742187);

		elseif(DiivSkinSettings.hbar1 == 7) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.4101562, 0.4921875);

		elseif(DiivSkinSettings.hbar1 == 8) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.328125, 0.4101562);

		elseif(DiivSkinSettings.hbar1 == 9) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.2460937, 0.328125);

		elseif(DiivSkinSettings.hbar1 == 10) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.1640625, 0.2460937);

		elseif(DiivSkinSettings.hbar1 == 11) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.0820312, 0.1640625);

		elseif(DiivSkinSettings.hbar1 == 12) then
			DiivSkins_hbar1Texture:SetTexCoord(0.0, 1.0, 0.0, 0.0820312);
		end
	end
end
I then added the suggested <Scripts> to the original texture frame's xml. (better quote them too, just to be safe)

Code:
		<Scripts>
			<OnLoad>
				this:RegisterEvent("VARIABLES_LOADED");
			</OnLoad>
			<OnEvent>
				if (event == "VARIABLES_LOADED") then 
					DiivSkins_hbar1Update(); 
				end
			</OnEvent>
		</Scripts>
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.

Last edited by diiverr : 06-09-05 at 08:56 AM.
diiverr is offline   Reply With Quote
Unread 06-09-05, 08:42 AM   #10
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
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)

Last edited by diiverr : 06-09-05 at 08:49 AM.
diiverr is offline   Reply With Quote
Unread 06-09-05, 09:08 AM   #11
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 442
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.
Gello is online now   Reply With Quote
Unread 06-09-05, 09:25 AM   #12
Gello
A Scalebane Royal Guard
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 442
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.

Last edited by Gello : 06-09-05 at 09:28 AM.
Gello is online now   Reply With Quote
Unread 06-09-05, 10:05 AM   #13
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
try the following code.

Your skinnable bar ----------
Code:
<Frame name="DiivSkins_hbar1" frameStrata="BACKGROUND" inherits="DiivSkins_hbarTemplate" parent="UIParent">
	<Size><AbsDimension x="512" y="46"/></Size>
	<Layers><Layer level="ARTWORK"><Texture name="DiivSkins_hbar1Texture" file="Interface\AddOns\DiivSkins\Skins\diivskins_01"><TexCoords left="0.0019531" right="1.0" top="0.0" bottom="0.0898437"/></Texture></Layer></Layers>
	<Anchors><Anchor point="BOTTOM"><Offset><AbsDimension x="215" y="550"/></Offset></Anchor></Anchors>
    <Scripts><OnLoad>this:RegisterEvent("VARIABLES_LOADED");</OnLoad><OnEvent>DS_TextureOnEvent();</OnEvent></Scripts>
</Frame>
your slider ------------------------
Code:
<Slider name="DiivSkins_hbar1Slider" inherits="OptionsSliderTemplate" minValue="2" maxValue="12" defaultValue="2" valueStep="1">
	<Size><AbsDimension x="160" y="17"/></Size>
	<Anchors><Anchor point="CENTER"/></Anchors>
	<Scripts>
		<OnLoad>
			getglobal(this:GetName().."Text"):SetText("Horizontal Bar 1");
			getglobal(this:GetName().."High"):SetText("12 slots");
			getglobal(this:GetName().."Low"):SetText("2 slot");
		</OnLoad>
		<OnShow>this:SetValue(DiivSkinSettings.hbar1);</OnShow>
		<OnValueChanged>
			DiivSkinSettings.hbar1 = this:GetValue();
			DiivSkins_TextureUpdate();
		</OnValueChanged>
	</Scripts>
</Slider>
and finally, the lua code ----------
Code:
-- Global Functions ---------------------------------------
function DS_FirstLoad()
	GameMenuFrame:Show();
	DS_Init:Show();
	DS_GameMenuButton:Hide();
	DS_GameMenuButton_Init:Show();
end
function DS_TextureOnEvent()
	if (event == "VARIABLES_LOADED") then 
		if (not DiivSkinSettings) then 
			DiivSkinSettings = {};
			DiivSkinSettings.hbar1 = 2;
			DS_FirstLoad();
		end
		DS_TextureUpdate();
	end
end
function DS_TextureUpdate()
	local key = DiivSkinSettings.hbar1;
	local var = DiivSkinTextures[key];
	DiivSkins_hbar1Texture:SetTexCoord(var.a, var.b, var.c, var.d);
end
-- Configuration Variables ---------------------------------
DiivSkinTextures = {};
DiivSkinTextures[2] = {a = 0.0, b = 1.0, c = 0.8984375, d = 0.9882812);
DiivSkinTextures[3] = {a = 0.0, b = 1.0, c = 0.8085937, d = 0.8984375);
DiivSkinTextures[4] = {a = 0.0, b = 1.0, c = 0.71875, d = 0.8085937);
DiivSkinTextures[5] = {a = 0.0, b = 1.0, c = 0.6289062, d = 0.71875);
DiivSkinTextures[6] = {a = 0.0, b = 1.0, c = 0.5390625, d = 0.6289062);
DiivSkinTextures[7] = {a = 0.0, b = 1.0, c = 0.4492187, d = 0.5390625);
DiivSkinTextures[8] = {a = 0.0, b = 1.0, c = 0.359375, d = 0.4492187);
DiivSkinTextures[9] = {a = 0.0, b = 1.0, c = 0.2695312, d = 0.359375);
DiivSkinTextures[10] = {a = 0.0, b = 1.0, c = 0.1796875, d = 0.2695312);
DiivSkinTextures[11] = {a = .0, b = 1.0, c = 0.0898437, d = 0.1796875);
DiivSkinTextures[12] = {a = 0.0, b = 1.0, c = 0.0, d = 0.0898437);
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

Last edited by Beladona : 06-09-05 at 10:10 AM.
Beladona is offline   Reply With Quote
Unread 06-09-05, 11:34 AM   #14
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67


Holy crap, I love you guys.

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. )

Last edited by diiverr : 06-09-05 at 11:38 AM.
diiverr is offline   Reply With Quote
Unread 06-10-05, 12:15 AM   #15
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
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.

-- the bar --
Code:
<Frame name="DiivSkins_hbar1" frameStrata="BACKGROUND" inherits="DiivSkins_hbarTemplate" parent="UIParent">
	<Size>
		<AbsDimension x="512" y="46"/>
	</Size>
	<Layers>
		<Layer level="ARTWORK">
			<Texture name="DiivSkins_hbar1Texture" file="Interface\AddOns\DiivSkins\Skins\diivskins_01">
				<TexCoords left="0.0019531" right="1.0" top="0.0" bottom="0.0820312"/>
			</Texture>
		</Layer>
	</Layers>
	<Anchors>
		<Anchor point="BOTTOM">
			<Offset>
				<AbsDimension x="215" y="550"/>
			</Offset>
		</Anchor>
	</Anchors>
	<Scripts>
		<OnLoad>
			this:RegisterEvent("VARIABLES_LOADED");
		</OnLoad>
		<OnEvent>
			DS_TextureOnEvent();
		</OnEvent>
	</Scripts>
</Frame>
-- the slider --
Code:
<Slider name="DiivSkins_hbar1Slider" inherits="OptionsSliderTemplate" minValue="1" maxValue="12" defaultValue="2" valueStep="1">
	<Size>
		<AbsDimension x="160" y="17"/>
	</Size>
	<Anchors>
		<Anchor point="CENTER"/>
	</Anchors>
	<Scripts>
		<OnLoad>
			getglobal(this:GetName().."Text"):SetText("Horizontal Bar 1");
			getglobal(this:GetName().."High"):SetText("12 slots");
			getglobal(this:GetName().."Low"):SetText("1 slot");
		</OnLoad>
		<OnShow>
			this:SetValue(DiivSkinSettings.hbar1);
		</OnShow>
		<OnValueChanged>
			if DiivSkinSettings then
				DiivSkinSettings.hbar1 = this:GetValue();
				DiivSkins_TextureUpdate();
			end
		</OnValueChanged>
	</Scripts>
</Slider>
-- the lua --
Code:
-- Variables ---------------------------------------
DiivSkinSettings = {};
DiivSkinSettings.hbar1 = 1

-- Global Functions ---------------------------------------
function DS_FirstLoad()
	DS_ControlConsole:Show();
	DS_startup:Show();
end
function DS_TextureOnEvent()
	if (event == "VARIABLES_LOADED") then 
		if (not DiivSkinSettings) then 
			DiivSkinSettings = {};
			DiivSkinSettings.hbar1 = 1;
			DS_FirstLoad();
		end
		DS_TextureUpdate();
	end
end
function DS_TextureUpdate()
	local key = DiivSkinSettings.hbar1;
	local var = DiivSkinTextures[key];
	DiivSkins_hbar1Texture:SetTexCoord(var.a, var.b, var.c, var.d);
end
-- Configuration Variables ---------------------------------
DiivSkinTextures = {};
DiivSkinTextures[2] = {a = 0.0, b = 1.0, c = 0.8984375, d = 0.9882812};
DiivSkinTextures[3] = {a = 0.0, b = 1.0, c = 0.8085937, d = 0.8984375};
DiivSkinTextures[4] = {a = 0.0, b = 1.0, c = 0.71875, d = 0.8085937};
DiivSkinTextures[5] = {a = 0.0, b = 1.0, c = 0.6289062, d = 0.71875};
DiivSkinTextures[6] = {a = 0.0, b = 1.0, c = 0.5390625, d = 0.6289062};
DiivSkinTextures[7] = {a = 0.0, b = 1.0, c = 0.4492187, d = 0.5390625};
DiivSkinTextures[8] = {a = 0.0, b = 1.0, c = 0.359375, d = 0.4492187};
DiivSkinTextures[9] = {a = 0.0, b = 1.0, c = 0.2695312, d = 0.359375};
DiivSkinTextures[10] = {a = 0.0, b = 1.0, c = 0.1796875, d = 0.2695312};
DiivSkinTextures[11] = {a = .0, b = 1.0, c = 0.0898437, d = 0.1796875};
DiivSkinTextures[12] = {a = 0.0, b = 1.0, c = 0.0, d = 0.0820312};
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:
[string "DiivSkins_hbar1Slider:OnValueChanged"]:2: attempt to index global `DiivSkins_TextureUpdate' (a nil value)
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.

I appreciate the help folks.
diiverr is offline   Reply With Quote
Unread 06-10-05, 04:17 AM   #16
greycap
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
function name in LUA:
DS_TextureUpdate()


function name in XML:
DiivSkins_TextureUpdate();


result: DiivSkins_TextureUpdate a nil value

reason? doesnt exist.




oh, and as to why it works in the first place and not when its changed? youre calling the correct function (DS_TextureUpdate()) from within DS_TextureOnEvent().

Last edited by greycap : 06-10-05 at 04:42 AM.
greycap is offline   Reply With Quote
Unread 06-10-05, 04:46 AM   #17
greycap
A Deviate Faerie Dragon
Join Date: Jun 2005
Posts: 11
How many lua scripters does it take to turn on a light?

3 to try and figure out whats wrong with the bulb, and one to turn on the switch.
greycap is offline   Reply With Quote
Unread 06-10-05, 06:25 AM   #18
diiverr
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 67
ROFL. In all fairness, I did say I was tired last night.

Works a treat now. thanks Greycap.

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.

Last edited by diiverr : 06-10-05 at 06:40 AM.
diiverr is offline   Reply With Quote
Unread 06-10-05, 07:15 AM   #19
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
one problem. You changed your step to 1-12 instead of 2-12 like it was before. In the bottom configuration variables, you need to add:

DiivSkinTextures[1] = {a = 0.0, b = 1.0, c = 0.8984375, d = 0.9882812}; (or whatever the texture coordinates are for that texture)

Otherwise when they select 1 on the slider, it will return an error because there is no corresponding configured texture for the value of 1.

Also, you added variables to the very top of the lua script. If you define

DiivSkinSettings = {};
DiivSkinSettings.hbar1 = 1

it will reset the options they have configured every time they load. Leave it in the OnLoad statement as it will detect if the value is there, and if not it will add it.

Last edited by Beladona : 06-10-05 at 07:18 AM.
Beladona is offline   Reply With Quote
Unread 06-10-05, 07:30 AM   #20
Beladona
A Molten Giant
 
Beladona's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 539
just an example, as I dont know the real texture coordinates you are wanting to use...

-- the bar --
Fine as it is, no changes necessary

-- the slider --
* changed DiivSkins_TextureUpdate(); to DS_TextureUpdate();
Code:
<Slider name="DiivSkins_hbar1Slider" inherits="OptionsSliderTemplate" minValue="1" maxValue="12" defaultValue="2" valueStep="1">
	<Size><AbsDimension x="160" y="17"/></Size>
	<Anchors><Anchor point="CENTER"/></Anchors>
	<Scripts>
		<OnLoad>
			getglobal(this:GetName().."Text"):SetText("Horizontal Bar 1");
			getglobal(this:GetName().."High"):SetText("12 slots");
			getglobal(this:GetName().."Low"):SetText("1 slot");
		</OnLoad>
		<OnShow>this:SetValue(DiivSkinSettings.hbar1);</OnShow>
		<OnValueChanged>
			DiivSkinSettings.hbar1 = this:GetValue();
			DS_TextureUpdate();
		</OnValueChanged>
		</Scripts>
	</Slider>
-- 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

Code:
-- Global Functions ---------------------------------------
function DS_FirstLoad()
	DS_ControlConsole:Show();
	DS_startup:Show();
	DiivSkinSettings.setup = true;
end
function DS_TextureOnEvent()
	if (event == "VARIABLES_LOADED") then 
		if (not DiivSkinSettings) then DiivSkinSettings = {}; end
		if (not DiivSkinSettings.hbar1) then DiivSkinSettings.hbar1 = 1; end
		if (not DiivSkinSettings.setup) then DS_FirstLoad(); end
		DS_TextureUpdate();
	end
end
function DS_TextureUpdate()
	local key = DiivSkinSettings.hbar1;
	local var = DiivSkinTextures[key];
	DiivSkins_hbar1Texture:SetTexCoord(var.a, var.b, var.c, var.d);
end
-- Configuration Variables ---------------------------------
DiivSkinTextures = {};
DiivSkinTextures[1] = {a = 0.0019531, b = 1.0, c = 0.0, d = 0.0820312};
DiivSkinTextures[2] = {a = 0.0, b = 1.0, c = 0.8984375, d = 0.9882812};
DiivSkinTextures[3] = {a = 0.0, b = 1.0, c = 0.8085937, d = 0.8984375};
DiivSkinTextures[4] = {a = 0.0, b = 1.0, c = 0.71875, d = 0.8085937};
DiivSkinTextures[5] = {a = 0.0, b = 1.0, c = 0.6289062, d = 0.71875};
DiivSkinTextures[6] = {a = 0.0, b = 1.0, c = 0.5390625, d = 0.6289062};
DiivSkinTextures[7] = {a = 0.0, b = 1.0, c = 0.4492187, d = 0.5390625};
DiivSkinTextures[8] = {a = 0.0, b = 1.0, c = 0.359375, d = 0.4492187};
DiivSkinTextures[9] = {a = 0.0, b = 1.0, c = 0.2695312, d = 0.359375};
DiivSkinTextures[10] = {a = 0.0, b = 1.0, c = 0.1796875, d = 0.2695312};
DiivSkinTextures[11] = {a = .0, b = 1.0, c = 0.0898437, d = 0.1796875};
DiivSkinTextures[12] = {a = 0.0, b = 1.0, c = 0.0, d = 0.0820312};
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.

Last edited by Beladona : 06-10-05 at 07:35 AM.
Beladona is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » What am I missing?

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