Thread Tools Display Modes
12-30-06, 04:30 PM   #1
PJizzle
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 5
Stuck on Setting Variable Data and Reading them.

Hi,

I'm trying to Set my Variables OnLoad Here's my code

In the GuildRecruit_Loaded() I set my default values and save them out.
Each of my option boxes (frames) has an OnLoad to function GuildRecruit_OptionsOnLoad()

But when that function starts I get and I get an "attempt to index global 'GuildRecruit_PostOptions' (a nil value). It seems that It's not reading the saved variables.

Any Suggestions???

function GuildRecruit_OnEvent(self, event, ...)
if (event == "VARIABLES_LOADED") then
GuildRecruit_Loaded();
end
end

--[[ PROPAGATE DEFAULTS AND SAVED DATA ]]
function GuildRecruit_Loaded()

-- SET VARIABLES AND DEFAULTS
if (not GuildRecruit_AdOptions) then --AD OPTIONS DEFAULT CHECK AND LOAD
GuildRecruit_AdOptions = GuildRecruit_Defaults["AdOptions"];
DEFAULT_CHAT_FRAME:AddMessage("GuildRecruit AD Options database not found. Generating...");
end

if (not GuildRecruit_PostOptions) then --POST RULES OPTIONS DEFAULT CHECK AND LOAD
GuildRecruit_PostOptions = setglobal(GuildRecruit_Defaults["PostOptions"]);
DEFAULT_CHAT_FRAME:AddMessage("GuildRecruit POST Options database not found. Generating...");
end

if (not GuildRecruit_LinkOptions) then --LINK OPTIONS DEFAULT CHECK AND LOAD
GuildRecruit_LinkOptions = GuildRecruit_Defaults["LinkOptions"];
DEFAULT_CHAT_FRAME:AddMessage("GuildRecruit LINK Options database not found. Generating...");
end

end
--[[ END PROPAGATE DEFAULTS AND SAVED DATA ]]


--[[ BEGIN READING THROUGH SAVED VARIABLES ]]
function GuildRecruit_OptionsOnLoad()
-- LOAD DATA TO OPTIONS BEGIN
local LoadedOptionBox = this:GetName();

if (LoadedOptionBox == "GuildRecruitROption") then --ON POST OPTIONS LOAD PROPAGATE VARAIBLES
for i=1,12 do
local Rtextinput = getglobal("GuildRecruitROption_Text"..i);
local Rtexttemp = "PTxt"..i.."";
local Rtextinputvalue = GuildRecruit_PostOptions[Rtexttemp];
Rtextinput:SetText(Rtextinputvalue);

local Renableinput = getglobal("GuildRecruitROption_Enable"..i);
local Renabletemp = "P"..i.."";
local Renableinputvalue = GuildRecruit_PostOptions[Renabletemp];
Renableinput:SetChecked(Renableinputvalue);
end
out("Loaded Options: "..LoadedOptionBox);

elseif (LoadedOptionBox == "GuildRecruitLOption") then --ON LINKS OPTIONS LOAD PROPAGATE VARAIBLES
for i=1,10 do
local Ltextinput = getglobal("GuildRecruitLOption_Text"..i);
local Ltexttemp = "LTxt"..i.."";
local Ltextinputvalue = GuildRecruit_LinkOptions[Ltexttemp];
out("L feedback: "..Ltexttemp);
Ltextinput:SetText(Ltextinputvalue);

local Lenableinput = getglobal("GuildRecruitLOption_Enable"..i);
local Lenabletemp = "L"..i.."";
local Lenableinputvalue = GuildRecruit_LinkOptions[Lenabletemp];
Lenableinput:SetChecked(Lenableinputvalue);
end
out("Loaded Options: "..LoadedOptionBox);

elseif (LoadedOptionBox == "GuildRecruitAdOptions") then --ON AD OPTIONS LOAD PROPAGATE VARAIBLES
GuildRecruitAdOptions_AdPanel_AdMultiplier:SetText(GuildRecruit_AdOptions["AdMultiplierVal"])
GuildRecruitAdOptions_AdPanel_AdChatNumber:SetText(GuildRecruit_AdOptions["ChanNumVal"]);
GuildRecruitAdOptions_AdMessageEdit:SetText(GuildRecruit_AdOptions["AdMessageVal"]);

out("Loaded Options: "..LoadedOptionBox);
end
-- LOAD DATA TO OPTIONS END
end
Please help thanks.


PJ
  Reply With Quote
01-08-07, 09:16 AM   #2
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Hum, not sure I've undestood...
To check if stored options exists and are loaded, I would use:

if (GuildRecruit_PostOptions == nil) then... Not Found
  Reply With Quote
01-08-07, 11:09 AM   #3
Sent_
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 6
If I understood you have:
GuildRecruit_OptionsOnLoad() - Called as <OnLoad> script for your frame(s)
GuildRecruit_Loaded() - Called when VARIABLES_LOADED is fired

The problem is in the GuildRecruit_PostOptions variable, which is initializaed by GR_Loaded() and used by GR_OptionsOnLoad().

Excuse me but, AFAIK, <OnLoad> sections are executed before VARIABLE_LOADED is fired.
If you don't have a default GR_PostOptions loading somewhere before <OnLoad> this error will always occur.

Let me say that using saved variables before that VARIABLES_LOADED is fired may cause headaches.
  Reply With Quote
01-08-07, 10:55 PM   #4
Riraito
An Aku'mai Servant
 
Riraito's Avatar
Join Date: Dec 2006
Posts: 32
I think that you can just declare the variables at the beginning of the file ( GuildRecruit_PostOptions = {'whatever goes in this variable'} etc) not in any functions or anything , then any saved variables will override those as soon as there loaded
  Reply With Quote
01-19-07, 01:40 PM   #5
PJizzle
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 5
Thanks,

I'll go through my code and clean house a little bit.


PJ
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stuck on Setting Variable Data and Reading them.

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