Saturday, April 21, 2012

XML and LUA

Quick question, is it possible to make a table of references to XML fontstrings, sliders, text-boxes in lua?|||http://home.blarg.net/~tyroney/wow/uitutorial/

is this what your looking for?|||Quote:








http://home.blarg.net/~tyroney/wow/uitutorial/

is this what your looking for?






Not really, I've made my whole addon using XML for the graphics, and don't want to convert it all to LUA if I don't have to. I'm trying to condense code in my add-on, and it requires me to use tables and in turn put XML elements in a table. For instance if CustomOneInput, CustomTwoInput, and CustomThreeInput were all XML textboxes, I'm trying to do something like this:


Code:
CustomInputs={CustomOneInput, CustomTwoInput, CustomThreeInput}
CustomNums={CustomOneNum,CustomTwoNum, CustomThreeNum};

--assume that these are in an Options GUI and CustomInputs have been collected from the GUI and inserted into the table.

function getInfo()
for i=1,#RR_CustomInputs do
if(RR_CustomInputs[i]~="") then
RR_CustomNums[i]=RR_CustomNums[i]:GetValue();
else
RR_CustomNums[i]=RR_DEFAULT_CUSTOM; --default value
end
end
end

The Problem occurs when I try to use an XML method with my table. Any help would be appreciated, I hope that's clear.|||Anyone have an idea?|||I have no idea. But you say the problem occurs and don't say what the problem is or what happens.|||Oh sorry, I get a syntax error when I try to save my Options GUI (when the method is called) for the line:


Code:
RR_CustomNums[i]=RR_CustomNums[i]:GetValue();

The actual error says: "attempt to index field '?' (a nil value)"|||3 ideas off the top of my head :

1.) You've defined CustomInputs as a Table, but then refer to RR_CustomInputs ?

Is there some kind of meta-reference or something ? Or am I drunk ? Yes, you're drunk.

2.) You've defined CustomInputs in your LUA outside of any function.

Assuming that your AddOn is loading the LUA file BEFORE the XML file, then the variables you are adding to the CustomInputs Table will be nil values, because the XML elements haven't been defined yet.

I would define the table after the VARIABLES_LOADED event, so you know the XML has been parsed and loaded and all the elements exist.

3.) Just off the top of my head, does :GetValue() work with TextBoxes ? I've always used :GetText()

Maybe I'm just being too literal and you're saying :GetValue() as an example :)



It's late - sorry if I've misunderstood you, and my ideas are just plain silly ;)



Feel free to post an actual XML and LUA code example :)|||Quote:








2.) You've defined CustomInputs in your LUA outside of any function.

Assuming that your AddOn is loading the LUA file BEFORE the XML file, then the variables you are adding to the CustomInputs Table will be nil values, because the XML elements haven't been defined yet.

I would define the table after the VARIABLES_LOADED event, so you know the XML has been parsed and loaded and all the elements exist.




Pretty sure that was the problem, I think I've fixed it now. Thank you very much.

No comments:

Post a Comment