Thread Tools Display Modes
12-10-22, 12:23 PM   #1
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Question New to Lua, Creating Addons for WoW, Advice Request

Hello,

So I have basically been playing WoW since Vanilla, but haven't ever looked at Lua, or how to create addons for wow until now.

I have bought the Lua 5.1 Reference Manual, although it's got delayed/lost in the post possibly was supposed to arrive thursday from Amazon, but hasn't yet!

Anyway I want to learn Lua, and how to create addons for WoW, I feel there is a lot I just don't understand.

Does anyone have any advice on what I should be reading to get an understanding of Lua, World of Warcraft Addons, plus anything else you think I should know before attempting to write an addon, or attempt to fix another addon.

I noticed there is a lot of Libraries like Ace3 and so on that a lot of Addons seem to use.

I would very much appreciate being pointed in the right direction to things I should read, or books I should get to gain a better understanding.
  Reply With Quote
12-10-22, 12:31 PM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
There is not much you can buy. It's mainly looking at other ppl code and trying to understand what they're doing.

A good source to find examples for certain things is:
https://wowpedia.fandom.com/wiki/World_of_Warcraft_API

Another good way is to look at the blizzard code of the element you want to work with:
https://github.com/Gethe/wow-ui-source/

So, get a small addon, see how it works and change it a little bit

For Ace3 there are some examples available, too:
https://www.wowace.com/projects/ace3...options-tables
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
12-10-22, 03:28 PM   #3
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Originally Posted by Rilgamon View Post
There is not much you can buy.
I expected this answer, obviously not the answer I was wanting to hear, but meh.

Just out of interest, what would your thoughts be on these books, I appreciate they are old and likely out of date now, but I thought it might help as maybe some stuff is still relevant?

https://wowprogramming.com/store.html

Originally Posted by Rilgamon View Post
It's mainly looking at other ppl code and trying to understand what they're doing.
This I have tried, and I can't seem to get my head around what it is they are doing mostly. It seems a lot of addon author's have yet to discover meaning comments, other addon authors don't comment at all.

I have programming experience, but there seems to be a distinct lack of documentation from the horses mouth so to speak, all the documentation is from third party sources that have somehow figured stuff out for themselves.

I tried to figure out how to add a simple button to the world map, AtlasLoot does this how I would like to, and it seems to use this Krowi_WorldMapButtons library, but there appears to be a slight variation in the code that does that, from the example code on the link posted, also the example code on the link doesn't actually work it gives me errors that aren't very descriptive.

On a more positive note, I have a new found respect for the efforts of the addons I do use that are still working and actively being updated.

Originally Posted by Rilgamon View Post
A good source to find examples for certain things is:
https://wowpedia.fandom.com/wiki/World_of_Warcraft_API

Another good way is to look at the blizzard code of the element you want to work with:
https://github.com/Gethe/wow-ui-source/
Thanks, I have seen those and have bookmarked them, but thanks for the heads up.

Originally Posted by Rilgamon View Post
So, get a small addon, see how it works and change it a little bit
Any recommendations for small addons?

Originally Posted by Rilgamon View Post
For Ace3 there are some examples available, too:
https://www.wowace.com/projects/ace3...options-tables
Thanks, I will bookmark this and have a read of it also.
  Reply With Quote
12-10-22, 04:00 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
A simple button on the WorldMapFrame:

Lua Code:
  1. local f = CreateFrame("Button", "AeroMaxxMapButton", WorldMapFrame, "UIPanelButtonTemplate") -- Create a standard Wow style red button (UIPanelButtonTemplate) with the name AeroMaxxMapButton and parent it to the WorldMapFrame
  2. f:SetSize(100, 25) -- Obvious
  3. f:SetFrameStrata("HIGH") -- Set the button high enought in the strata/Level stacks to be seen
  4. f:SetFrameLevel(511)
  5. f:SetPoint("TOPLEFT", 100, 0) -- Position the button's TOPLEFT corner relative to the TOPLEFT of the MapFrame (parent)
  6. f:SetText("Click Me!") -- Give it some text
  7. f:SetScript("OnClick", function(self) -- Tell the button what to do when you click it
  8.     print("You clicked the:", self:GetName())
  9. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-10-22, 05:00 PM   #5
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Originally Posted by Fizzlemizz View Post
A simple button on the WorldMapFrame:

Lua Code:
  1. local f = CreateFrame("Button", "AeroMaxxMapButton", WorldMapFrame, "UIPanelButtonTemplate") -- Create a standard Wow style red button (UIPanelButtonTemplate) with the name AeroMaxxMapButton and parent it to the WorldMapFrame
  2. f:SetSize(100, 25) -- Obvious
  3. f:SetFrameStrata("HIGH") -- Set the button high enought in the strata/Level stacks to be seen
  4. f:SetFrameLevel(511)
  5. f:SetPoint("TOPLEFT", 100, 0) -- Position the button's TOPLEFT corner relative to the TOPLEFT of the MapFrame (parent)
  6. f:SetText("Click Me!") -- Give it some text
  7. f:SetScript("OnClick", function(self) -- Tell the button what to do when you click it
  8.     print("You clicked the:", self:GetName())
  9. end)
Thanks for the reply.

I was kinda hoping to use this library, but for the life of me can I get it to work!

Others are using it however, but I can't seem to figure out what I am doing differently.

https://www.curseforge.com/wow/addon...ld-map-buttons
https://addonswow.com/krowis-world-map-buttons
https://github.com/TheKrowi/Krowi_WorldMapButtons
  Reply With Quote
12-10-22, 05:59 PM   #6
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Addonswow.com is not a valid site to get addons. It's entire collection is just rehosted from other sites and rarely are the addons there up-to-date.

As for getting the library to work, we can't help you if you don't share your entire code and specify what you are doing, what you did, the results you expect, and the results you're getting. Do you have the basics of creating and loading an addon into WoW? Are you saving the file you edited and then reloading the UI when you make changes? Did you read and understand everything on that GitHub page from the author? Did you try getting those examples working first before changing things?

WoW addon development is more involved than just learning a coding language, it takes patience and an understanding of the parts between the lines of code and actually doing something on screen. I uploaded my first addon July 2015, and that was after deciding to learn to make one over the holiday break at the end of 2014. I didn't consider myself "advanced" until years later, and even then, XML still scares me and I refused to use it when making visual stuff. Hell, just digging around the big boy addons confuses the hell out of me. I also refuse to use libraries unless I absolutely have to, like supporting shared media. Learn how to do the simple stuff first before relying on another addon (love the contradictory statement on that Github page, "install this addon so you don't have to rely on an addon" lol).

I self taught myself with wowprogramming.com before it shut down. Since then, all my learning is from digging into other addons, including Blizzard's code extract, and loads of random wiki reads. It also helps that I maintain a personal addon that has grown into thousands of lines of code doing all sorts of random things. It started as just an amalgamation of all the tiny addons I had, some were just a few lines of code, and I was cleaning up my addon list. If it helps for you to read a Lua guide, that's fine, just keep in mind Lua by itself, the barebones language, is tiny. Vast majority of what you need to learn is what Blizzard has implemented. If you want to learn and understand Lua by itself first, you can check out the official manual online here.
  Reply With Quote
12-11-22, 11:31 AM   #7
AeroMaxxD
An Aku'mai Servant
Join Date: Dec 2022
Posts: 33
Originally Posted by Kanegasi View Post
Addonswow.com is not a valid site to get addons. It's entire collection is just rehosted from other sites and rarely are the addons there up-to-date.
That's fine it was just a link I found.

Originally Posted by Kanegasi View Post
Do you have the basics of creating and loading an addon into WoW?
Yes, although this is really a yes and no answer, basically I know there needs to be a toc file in the folder just from looking at other addons, as to the structure as to what should be in this file I only know what I seen in other addons.

Originally Posted by Kanegasi View Post
As for getting the library to work, we can't help you if you don't share your entire code and specify what you are doing, what you did, the results you expect, and the results you're getting.
Sure, I understand that. My personal feeling is that I need a better understanding of Lua in general. This can only be a good thing surely? I mean I can't go too far wrong from learning Lua generally, maybe I would have an easier time learning the wow-specific stuff from that point on.

Originally Posted by Kanegasi View Post
Are you saving the file you edited and then reloading the UI when you make changes?
Yes, should I not do that?

Originally Posted by Kanegasi View Post
Did you read and understand everything on that GitHub page from the author? Did you try getting those examples working first before changing things?
I read everything on the GitHub page, but sadly only understood it partially. I created an addon "WorldMapButton" and .toc, .lua, .xml files with the same name as the folder, and then copied and pasted the example into the respective files, and logged into wow.

The example given doesn't give me any errors, but it also doesn't add a button to the world map.

I think I need to add something into the functions in the Mixin file in the example.

Also I wasn't sure if I was to include the .lua or .xml file(s) in the .toc file, so I just included the .xml file as this references the .lua files but unsure if that was correct or not.

Originally Posted by Kanegasi View Post
WoW addon development is more involved than just learning a coding language, it takes patience and an understanding of the parts between the lines of code and actually doing something on screen.
Sure I understand that, I just figured having spent approx. 5 days trying to figure stuff out every day approx. 5 hours each day on and off throughout the day I would have made more progress.

Originally Posted by Kanegasi View Post
I uploaded my first addon July 2015, and that was after deciding to learn to make one over the holiday break at the end of 2014. I didn't consider myself "advanced" until years later, and even then, XML still scares me and I refused to use it when making visual stuff. Hell, just digging around the big boy addons confuses the hell out of me. I also refuse to use libraries unless I absolutely have to, like supporting shared media. Learn how to do the simple stuff first before relying on another addon (love the contradictory statement on that Github page, "install this addon so you don't have to rely on an addon" lol).
My initial thought was to try and fix addons that hadn't been updated in a long time to work with DragonFlight, after realising this was harder to do that I first thought I decided I would scale things back a lot, I have an addon that adds a button to the world map to toggle HandyNotes pins, but it adds it in the same place another addon I have puts world maps coords for where my mouse is.

So I figured I would create an addon with the same functionality, but add the toggle button in a different place on the world map, the same place where all the other buttons are placed.

This in theory should be a fairly simple addon with very few lines of code IMO.

Originally Posted by Kanegasi View Post
I self taught myself with wowprogramming.com before it shut down. Since then, all my learning is from digging into other addons, including Blizzard's code extract, and loads of random wiki reads. It also helps that I maintain a personal addon that has grown into thousands of lines of code doing all sorts of random things. It started as just an amalgamation of all the tiny addons I had, some were just a few lines of code, and I was cleaning up my addon list. If it helps for you to read a Lua guide, that's fine, just keep in mind Lua by itself, the barebones language, is tiny. Vast majority of what you need to learn is what Blizzard has implemented. If you want to learn and understand Lua by itself first, you can check out the official manual online here.
I have the first edition of that wowprogramming book in print, and the 2nd edition as a pdf, I should also have the lua 5.1 reference manual in print soon, it was meant to arrive last thursday, but it appears to have got lost in the post.
  Reply With Quote
12-11-22, 03:53 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
A /reload or logout/on are required for any new code to "activate".

Only the .toc file needs to be the same name as the folder it is in. Files listed in the .toc can have whatever names work for you. They can also be in sub-folders and listed in the .toc as:
sub_folder-name\code_filename.lua

Only .lua and .xml files need to be listed in the .toc (or in an xml file that is included in the .toc).

Textures, sounds, fonts etc. used in the addon should be under the addon folder (sub-folder(s) again is fine) but not in the .toc as they will be referenced in code by their relative path.

Basic ## entries you shoud include in your .toc are:

Code:
## Interface: 100002 -- The curent .toc version of the game client you are targting (retail, classic-era, wrath)
## Title: Fizz -- The addon title to show up in the Addons list
## Author: Fizzlemizz -- You
## Version: 10.0.0 -- The version of your addon
Optional:
Code:
## Notes: Extra Fizz for my UI -- Display in a tooltip when you mouseover addons in the list
## SavedVariables: FIZZ_DATA -- If you are saving information for use between session [available to all you characters]
## SavedVariablesPerCharacter: FIZZ_CHAR_DATA -- As above but information is only available to the currently logged on character.
XML is not a requirement other than for inheriting as secure templates. You can create entire frame structures in lua. Neither is "better" so use what you feel most comfortable with (debugging lua generated frames is probably still a little better than xml but ...)

I'm also no a great user of libraries so I can't I can't help much there either.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-14-22, 03:01 AM   #9
Carnacki
A Kobold Labourer
 
Carnacki's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 1
Not sure what programming language you're used to, but as a VB/C#/MSSQL (visual studio) person I found that Addon Studio was a nice, familiar starting point. You get the visual designer that does a lot of work for you and you can focus on what you're trying to do.

https://addonstudio.fallenworlds.org/wiki/AddOn_Studio

They also have a very active discord presence: https://discord.com/invite/eAGb7Rc

The resulting addon is not as "lightweight" as handcoding in notepad++ but it's useful as a starting point. I personally tinkered with it for awhile to get more used to WoW Lua in general and then wrote my addon entirely in Lua.

Going through the Lua manual could be helpful, there are definitely some things that Lua does differently to VB (for example). So getting your head around basic syntax rules definitely helps.

As for your example, you mentioned not getting any errors. I assume you're using bugsack and buggrabber?
__________________
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » New to Lua, Creating Addons for WoW, Advice Request

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