H: Why XML and why LUA?
Greetings,
So ive read some books and some topics about LUA and XML. According to most information, LUA should be used for the behavior of an AddOn while XML is used for the Layout(Graphics) - however both can be used for either. Now my question would be; In cases like moving a frame, why is <OnDragStart> self:StartMoving() </OnDragStart> <OnDragStop> self:StopMovingOrSizing() </OnDragStop> used over the easy LUA way of doing this? function MakeMovable(frame) frame:SetMovable(true) frame:RegisterForDrag("LeftButton") frame:SetScript("OnDragStart", frame.StartMoving) frame:SetScript("OnDragStop", frame.StopMovingOrSizing) end now any other frames/buttons/w.e can be moved by just adding like the following code: local frame = CreateFrame("Button", "UIPanelButtonTemplateTest", UIParent, "UIPanelButtonTemplate") frame:SetHeight(20) frame:SetWidth(100) frame:SetText("Test Button") frame:ClearAllPoints() frame:SetPoint("CENTER", 0, 0) MakeMovable(frame) putting MakeMovable(frame) now makes the Button i just created Movable in the same manner as the one in XML, however the XML requires that i write it for each frame i create aswell as Register the Event, while this can just call the MakeMovable function. Maybe i don't quiete get the language yet, or is there an even simpler way to implement moveframes? Regards, fRodzet |
You just read the wrong guides :)
XML is not required and not used by many addons. |
I don't use xml in any of my addons simply because I don't know anything about xml coding :)
|
XML is a universal language that can be used in various applications and programming languages, whether to represent data or a graphical layout, like in WoW.
XML in WoW lua allows you to create templates for objects (frames etc), but you can use functions to get similar behaviour in lua. As far as I'm aware there is nothing you can do in XML that you can't replicate in lua (in this case). People who use XML to represent their GUI are often used to doing so in different environments. Habits tend to stick; it's not required to end a line with a semicolon in lua or wrap conditions in brackets, either, but Blizzard still does so in their own code. TL;DR: Do what you want :p |
Errors in XML can be a lot harder figure out where as for the most part it's pretty straight forward with LUA errors.
|
Allright, so if i'm reading the wrong guides.. which do you guys prefer? :)
Also all the AddOns that i looked at uses .XML for Graphics and minor Script Behaviours - DeadlyBossMods as for example. Ive read the wowprogramming.com book and just started at "Beginning Lua with World of Warcraft AddOns" - both instruct that you can use LUA for everything, but they also both recommend to learn XML as it somehow has some minor advantages in the Graphics section.. Anyways - i'd like a recommendation on where to start: Should i just go trough wowpedia.org and try to learn it from there, or should i read another book or what do you suggest? :) |
Best way to learn is to grab a simple addon, mess with parts of it and learn through trial and error how it works.
Or, that's how I did it. |
DeadlyBossMods is not a very good example. The addon works just fine, but the code is absolutely awful.
For some examples of addons with decent code and frames that don't use XML, take a look at BigWigs, Omen, Bartender4, TomTom, Mapster, or anything written by Haste or Tekkub. Both of those authors have a lot of small simple addons with clean code. Also, many of the code examples on Wowpedia are *really* outdated, and were written many years ago when you actually needed to use XML for a lot of things because the Lua frame API was incomplete. Nowadays, the only thing you can't do without XML is create templates for inheritance by secure frames, but that's a pretty advanced topic and you can generally achieve your goal without using templates anyway. The actual API reference on Wowpedia is fine, though. The only other reason you might use XML would be if you were already hooked on XML from some other realm of programming... though honestly I don't know any programmer who uses XML who wouldn't be ecstatic to never have to look at it ever again. It's great for readability for machines; not so much for humans. |
Quote:
I have a few other questions here: Is it possible to write an Addon where you create a .Lua file simply for all the functions and then create other .Lua files to call these functions. Example: A .Lua file named: MakeMovable.lua with the use of this code function MakeMovable(frame) frame:SetMovable(true) frame:RegisterForDrag("LeftButton") frame:SetScript("OnDragStart", frame.StartMoving) frame:SetScript("OnDragStop", frame.StopMovingOrSizing) end And then another .Lua file named e.g.: Button.lua and then call the function MakeMovable(frame) from the MakeMovable.lua file, like this local frame = CreateFrame("Button", "UIPanelButtonTemplateTest", UIParent, "UIPanelButtonTemplate") frame:SetHeight(20) frame:SetWidth(100) frame:SetText("Test Button") frame:ClearAllPoints() frame:SetPoint("CENTER", 0, 0) MakeMovable(frame) or do i have to keep these in the same file? |
As an example:
Top of first .Lua file Lua Code:
Second file Lua Code:
You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument. |
Quote:
Some links on where to start learning, which editors is good to use, maybe some books and other stuff would be very much appreciated! I am really in to learning this stuff, i find it very exciting! Isn't there a very good guide out there guiding you trough every single step of creating a WoWAddOn? Like first learn you the basics of lua, then explains the control structures, etc? :) |
Quote:
For editors, I prefer Notepad++. |
Quote:
WoW Interface and WoWAce / Curse have very active communities with a lot of dedicated forums and sub-forums if you need help with a specific question, or want to try to find specific information. So long as you describe your questions adequately, ask clear questions, post your code, you'll find the help you need. WoWwiki, WoWpedia, and WoWprogramming are going to be your best points of reference (at first). Each has articles on how to start an AddOn (.toc format etc). Keep in mind that LUA is a language independent of WoW, and as such, you can find a LOT of information on general coding websites, or dedicated LUA websites. Notepad++ is pretty cute. |
Quote:
|
WoWpedia is a bit more relevant than WoWwiki. I believe that WoWpedia was made, and is maintained by several people that moved on from WoWwiki(for whatever reason).
|
Quote:
|
Quote:
Code:
local Funs, Settings = unpack(select(2, ...)) Quote:
Quote:
I feel like an old geezer talking about this, "I've seen some things, man. And some stuff. I wouldn't recommend it." :rolleyes: |
Quote:
|
Quote:
Lua Code:
|
One further lesson...
I'ts Lua, not LUA. Lua is Portuguese for "moon", not an acronym. ;) |
All times are GMT -6. The time now is 11:42 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI