WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   H: Why XML and why LUA? (https://www.wowinterface.com/forums/showthread.php?t=46080)

fRodzet 03-19-13 03:57 PM

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

Rilgamon 03-19-13 04:22 PM

You just read the wrong guides :)
XML is not required and not used by many addons.

10leej 03-19-13 04:43 PM

I don't use xml in any of my addons simply because I don't know anything about xml coding :)

Haleth 03-19-13 04:53 PM

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

Fizzlemizz 03-19-13 05:37 PM

Errors in XML can be a lot harder figure out where as for the most part it's pretty straight forward with LUA errors.

fRodzet 03-19-13 06:01 PM

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? :)

10leej 03-19-13 06:07 PM

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.

Phanx 03-19-13 07:47 PM

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.

fRodzet 03-20-13 07:45 AM

Quote:

Originally Posted by Phanx (Post 274861)
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.

Thank you for such a useful reply! :) I will look into those AddOns :)

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?

Nibelheim 03-20-13 07:56 AM

As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.

fRodzet 03-20-13 08:04 AM

Quote:

Originally Posted by Nibelheim (Post 274877)
As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.

Ty! :)


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? :)

Nibelheim 03-20-13 08:56 AM

Quote:

Originally Posted by fRodzet (Post 274878)
Ty! :)


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? :)

Not that I've seen. There's the WoW Programming book, but I think it was written/updated back in WotLK. Their website is up to date, though.

For editors, I prefer Notepad++.

Clamsoda 03-20-13 09:20 AM

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?
I wouldn't suggest a book. You'll accomplish a lot more by experimenting, and looking around the internet. I don't know if it is because I am part of a younger generation or what not, but books as references are losing their appeal. You can find exponentially more relevant information on the internet, faster; and as such, the learning process is less impeded by the frustration of looking through a book.

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.

fRodzet 03-20-13 09:35 AM

Quote:

Originally Posted by Clamsoda (Post 274881)
I wouldn't suggest a book. You'll accomplish a lot more by experimenting, and looking around the internet. I don't know if it is because I am part of a younger generation or what not, but books as references are losing their appeal. You can find exponentially more relevant information on the internet, faster; and as such, the learning process is less impeded by the frustration of looking through a book.

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.

Thanks for the Answer! :) I didn't know there was a difference between WoWWiki and WoWPedia? I thought they were one and the same.. Is both sites relevant or is one the better pick? I'm sorry for all the newbish questions but i really want to make my first useable addon, and i have the greatest idea in mind and it annoys the **** out of me that i can't accomplish it yet. I know it is possible because ived studied other AddOns and my idea is pretty much a mixture of those AddOns, all in one :)

Clamsoda 03-20-13 10:03 AM

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

Resike 03-20-13 10:20 AM

Quote:

Originally Posted by Phanx (Post 274861)
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.

I disaggre, there is a bunch of stuff which you can't make in lua or toc, but only in xml.

SDPhantom 03-20-13 11:05 AM

Quote:

Originally Posted by Nibelheim (Post 274877)
As an example:

Top of first .Lua file
Lua Code:
  1. local addon, ns = ...
  2. local Funs, Settings = unpack(select(2, ...))
  3.  
  4. Settings.defaults = {
  5.    x = 0,
  6.    y = 0,
  7. }
  8.  
  9. Funs.updateSettings = function()
  10.     -- do stuff
  11. end

Second file
Lua Code:
  1. local Funs, Settings = unpack(select(2, ...))
  2.  
  3. local Init = function()
  4.     Funs.updateSettings()
  5.     print(Settings.x, Settings.y)
  6. end

You can now access thingies from any file within your addon, as each file in your addon shares a hidden passed argument.

From the code you posted, this starts an error propagating from the following line:
Code:

local Funs, Settings = unpack(select(2, ...))
This is because the shared addon table is empty and as such, both variables will be set to nil. Further code raises an attempt to index nil error.


Quote:

Originally Posted by fRodzet (Post 274878)
Ty! :)


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? :)

The websites mentioned are a good start. I've had experience with Lua prior to playing WoW at which I've learned from the documentation on Lua's official website. Note WoW uses Lua version 5.1 now. As far as books, as you've run into before, the WoW API is constantly evolving and books and guides will eventually become outdated as time passes.


Quote:

Originally Posted by Clamsoda (Post 274884)
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).

WoWWiki started out being hosted independently and was fine at that point. The problem started when they moved to be hosted by Wikia.com. From then, Wikia.com forced the site to undergo drastic layout changes many people hated, including several admins. It was then the admins branched off and made WoWPedia, which is hosted by Curse.com.

I feel like an old geezer talking about this, "I've seen some things, man. And some stuff. I wouldn't recommend it." :rolleyes:

Dridzt 03-20-13 11:35 AM

Quote:

Originally Posted by Resike (Post 274885)
I disaggre, there is a bunch of stuff which you can't make in lua or toc, but only in xml.

Like? There's one thing you can't do and it was already mentioned by Phanx.

Nibelheim 03-20-13 12:28 PM

Quote:

Originally Posted by SDPhantom (Post 274887)
From the code you posted, this starts an error propagating from the following line:
Code:

local Funs, Settings = unpack(select(2, ...))
This is because the shared addon table is empty and as such, both variables will be set to nil. Further code raises an attempt to index nil error.

Woops. Forgot a part. First file should be:
Lua Code:
  1. local addon, ns = ...
  2. ns[1] = {}
  3. ns[2] = {}
  4.  
  5. local Funs, Settings = unpack(select(2, ...))
  6.  
  7. Settings.defaults = {
  8.    x = 0,
  9.    y = 0,
  10. }
  11.  
  12. Funs.updateSettings = function()
  13.     -- do stuff
  14. end

Seerah 03-20-13 12:49 PM

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