From table to XML
Am developing my addon, Historia.
Have set up the database as I want it, but am now running into a problem. Can't figure out a decent way to put a table I have into the XML its supposed to go. Its basically a simple table with the players levels and a time when the player gained that level. Sure, I could define a 100 possible fontstring(s) in my XML file but there is problably a more elegant way to handle this. Also would like to do this without a scrolling table. Any help is appriciated. Lua Code:
|
Yes there is a simple way: don't use XML. XML is really only for setting up a frame that never changes, but you can do 99.9% of all frame related things in Lua, which is infinitely easier to read, and more importantly, debug.
In your ADDON_LOADED function (see my other post), assuming your saved variables in the ToC are called HistoriaDB, it should look something like this: Code:
function private_table.eventFrame:ADDON_LOADED(AddOn) |
If you want your saved variables' table structure to look more like your example, then change this line:
Code:
HistoriaDB["Level"] = {time = GetTime(), level = player_level} |
You forgot the end parenthesis on UnitName("player" :D
|
Quote:
Made my first frame in lua today, easy :o |
Quote:
"if not AddOn == MyAddOn then return end" 2nd time i see you posting that which wont work |
Quote:
That's because "not AddOn" evaluates to false if AddOn is non-nil and true otherwise. So that line is essentially saying "if false/true == MyAddOn then" which isn't at all what you want for a string comparison. :D |
I think it would be more didactic to mention that it is an operator precedence issue:
not (which is a unary operator, with the operand on the right side of the operator) will be evaluated in the expression before the == operator (which is a binary operator, with one operand to the left and one the right of the operator). And that is because not has a higher operator precedence than ==. http://www.lua.org/pil/3.5.html so not AddOn == MyAddOn is the same as (not Addon) == MyAddon instead of not (Addon == MyAddOn) When you want to change the evaluation order, you can use the parentheses like in the last expression. So Code:
if not (AddOn == MyAddOn) then |
Or just use
Code:
if AddOn ~= MyAddOn then |
Internally, these two do the exact same operations in the Lua engine. The only difference is the later is in C code for both operations instead of popping in and out of the Lua code. The result is the second is slightly faster than the first.
Code:
not (var1 == var2) Code:
var1 ~= var2 |
Took myrroddin's advice and coded part of my addon in lua instead of XML.
Would like to get the opinion of this community of how well I did. There is problably room for improvement :p This is the result of the coding (its part of a larger frame that is defined in XML). And this is the code: Lua Code:
|
You can add some readability and breathing room by breaking chunks into paragraphs. Also, when localizing, you can refer to the global strings, which are built-in localizations of common strings. For example, replace
Code:
HLML1:SetText(L['Level']) Code:
HLML1:SetText(LEVEL) A good start! |
All times are GMT -6. The time now is 10:13 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI