WoW:Getting started with writing AddOns: Difference between revisions

m
no edit summary
(→‎TOC File: clarification)
mNo edit summary
Line 1: Line 1:
{{cleanup|Needs to be less MS Windows-centric.}}
{{uiaddon}}
{{uiaddon}}
The idea of picking up any programming language can be daunting, and when you have to tie your program into someone else's APIs it can be nearly overwhelming. Creating your own AddOn will be a difficult process for novice coders, but the end satisfaction is worth it.  
The idea of picking up any programming language can be daunting, and when you have to tie your program into someone else's APIs it can be nearly overwhelming. Creating your own AddOn will be a difficult process for novice coders, but the end satisfaction is worth it.  


== First Steps ==  
== First Steps ==
These first step detail what someone might do to get started writing AddOns for World of Warcraft for the first time.


=== What should I make ===
Figure out what you want your AddOn to do. Don't try and get into the details too much, just decide what you want the overall goal to be. I usually start by asking myself these questions:
Figure out what you want your AddOn to do. Don't try and get into the details too much, just decide what you want the overall goal to be. I usually start by asking myself these questions:
* What's my end goal?
* What information will I need from WoW for my AddOn to work?
* Will I need to make custom frames?
* Will I need to interact with Blizzard's frames?
* Do I know the functions needed to do everything I want to do?


:*What's my end goal?
=== How do I make it ===
:*What information will I need from WoW for my AddOn to work?
Research the programming environment.
:*Will I need to make custom frames?
* Learn the WoW UI language, [[Lua]], by reading a few pages of the reference for the basic idea.
:*Will I need to interact with Blizzard's frames?
* Learn the WoW UI API, [[World of Warcraft API]] and UI constructs, by reading a bit from each section.
:*Do I know the functions needed to do everything I want to do?
* Learn the basic structure, as detailed below, also skimming [[WoW AddOn]] reference page for structure.
* Find a real but simple example, like from [[Curse]], to get a basic idea of what's evolved in a real AddOn.
* Make a barebones test AddOn to do something simple, using the reference material described above.


=== Get Your Information: The WoW API ===
The following sections help with some of the various aspects of completing these first steps.


Getting information from WoW is critical to making your AddOn function. The [[World of Warcraft API]] has a list of functions that will give you that information. These are your building blocks, and if you don't have a block you need (or thought you needed) then you'll have to find another way to get information for your AddOn. Don't be discouraged, as with any programming language there are many different ways to accomplish your goal, so keep looking until you find a way.
== Getting into the WoW API ==
Getting information on how the WoW UI works is critical to making your AddOn function. The [[World of Warcraft API]] has a list of functions that will give you that information. These are your building blocks, and if you don't have a block you need (or thought you needed) then you'll have to find another way to get information for your AddOn. Don't be discouraged, as with any programming language there are many different ways to accomplish your goal, so keep looking until you find a way.


You need to extract the Blizzard interface files. This will allow you to view all of the XML and Lua files that make the game's default UI work, as well as provide you with two introductory tutorials. To do this:
=== Getting the UI Source Code ===
:''See also [[Extracting interface files]] and [[Viewing Blizzard's interface code]].
You may want to extract the Blizzard interface files, where you can view all of the XML and Lua files that make the game's default UI work> This can be useful as example code and provides you with two introductory tutorials.


==== Open WoW with the console flag ====
==== Enable the WoW "console" ====
:''Note: the Battle.net launcher now has an option to launch in console mode, which can be used instead.''
===== For Windows =====
This section helps open WoW with the console flag enabled to use the WoW console, necessary for extracting the WoW interface.
:*Navigate to your <tt>World of Warcraft\</tt> directory (usually in <tt>"C:\Program Files (x86)"</tt>)
;For Windows
:*Right click the <tt>WoW.exe</tt> file
* Navigate to your WoW install directory, usually in 'C:\Program Files (x86)'.
:*'''Send to &rarr; Desktop (create shortcut)'''
* Right-click the 'WoW.exe' file
:*Navigate to your Desktop, right click on your newly created shortcut
* Click 'Send to &rarr; Desktop (create shortcut)'
:*Select '''Properties''', a new window will pop up
* Navigate to, or look at, your Desktop
:*In the target line you need to add '-console' to the very end of the line it should look like this:
* Right-click on your newly created shortcut
::<tt>"C:\Program Files (x86)\World of Warcraft\Wow.exe" -console</tt>
* Select 'Properties', a new window will pop up
:*Make sure to hit '''Apply''', close the window and launch your created shortcut
* In the target line you need to add '-console' to the very end of the line it should look similar to this:
"C:\Program Files (x86)\World of Warcraft\Wow.exe" -console
* Make sure to hit 'Apply', close the window and launch your created shortcut


===== For Mac OS X =====
;For Mac OS X
:*Open <tt>Terminal.app</tt> (located in <tt>/Applications/Utilities</tt>)
* Open 'Terminal.app', located in '/Applications/Utilities'.
:*Paste the following command and press return:
* Paste the following command and press return:
:**<tt>Open "/Applications/World of Warcraft/World of Warcraft-64.app" --args -console</tt>
Open "/Applications/World of Warcraft/World of Warcraft-64.app" --args -console
:*WoW will launch
* WoW will launch
:* Note that the command was tested with WoW [[Patch 5.0.5|5.0.5]] on Mac OS X 10.8
* Note that the command was tested with WoW [[Patch 5.0.5|5.0.5]] on Mac OS X 10.8


==== Extract the API ====
==== Extract the API ====
:*At the login page ('''before''' logging in) press the tilde (<tt>~</tt>) key (the key to left of the 1 key, labeled <sub><tt>`</tt></sub><sup><tt>~</tt></sup>) to open the World of Warcraft console
* At the login page ('''before''' logging in) press the tilde (<tt>~</tt>) key (the key to left of the 1 key, labeled <sub><tt>`</tt></sub><sup><tt>~</tt></sup>) to open the World of Warcraft console
:*Type "<tt>exportInterfaceFiles code</tt>" or "<tt>exportInterfaceFiles art</tt>". Code is probably what you're looking for, you will notice the game will lock up as it is exporting the files, this is normal.  
* Type "<tt>exportInterfaceFiles code</tt>" or "<tt>exportInterfaceFiles art</tt>". Code is probably what you're looking for, you will notice the game will lock up as it is exporting the files, this is normal.  
:*You can now find the current version of the stock UI files in the <tt>BlizzardInterfaceCode</tt> folder of your WoW directory.
* You can now find the current version of the stock UI files in the <tt>BlizzardInterfaceCode</tt> folder of your WoW directory.


== Editing Tools ==
== Editing Tools ==
Before you can write any sort of code, you'll want to have a tool that lets you edit your AddOn files.  All AddOn files are plain text files, meaning even Notepad will do.  You can also get LUA and XML specific text editors, which will highlight syntax for you, in turn making your coding a lot easier.
Before you can write any sort of code, you'll want to have a tool that lets you edit your AddOn files.  All AddOn files are plain text files, meaning even Notepad will do.  You can also get LUA and XML specific text editors, which will highlight syntax for you, in turn making your coding a lot easier.
To review the list of tools and get one you'd like, head to the [[Lua editors]] page.
To review the list of tools and get one you'd like, head to the [[Lua editors]] page.


== File Types ==
== File Types ==
There are three primary types of files that you'll need to worry about with AddOn editing:
There are three primary types of files that you'll need to worry about with AddOn editing:
* TOC File - This file is required for any AddOn. This is the file that supplies WoW with information about your AddOn and which files are required for your AddOn to work.
* TOC File - This file is required for any AddOn. This is the file that supplies WoW with information about your AddOn and which files are required for your AddOn to work.
Line 57: Line 67:


=== TOC File ===
=== TOC File ===
This is the file that instructs WoW in some basics about your AddOn and what other files you want loaded. Here's a short example of one:
This is the file that instructs WoW in some basics about your AddOn and what other files you want loaded. Here's a short example of one:


  ## Interface: 60100
  ## Interface: {{API LatestInterface}}
  <nowiki>##</nowiki> Title : My AddOn
  ## Title : My AddOn
  <nowiki>##</nowiki> Notes: This AddOn does nothing but display a frame with a button
  ## Notes: This AddOn does nothing but display a frame with a button
  <nowiki>##</nowiki> Author: My Name
  ## Author: My Name
  myAddOn.xml
  myAddOn.xml
  <nowiki>#</nowiki> This is a comment. Interface: 60100 refers to WoW client version 6.1
  # This is a comment. Interface: 60100 refers to WoW client version 6.1


You can read more about what you need or can put in a TOC over at [[The TOC Format]]
You can read more about what you need or can put in a TOC over at [[The TOC Format]]


=== Lua Files ===
=== Lua Files ===
[[Lua]] files contain functional pieces of code. You may choose to only have one of these or break up your code into multiple files for a specific purpose. Here's a short example of one:
[[Lua]] files contain functional pieces of code. You may choose to only have one of these or break up your code into multiple files for a specific purpose. Here's a short example of one:


  function MyAddon_OnLoad()
  function MyAddon_OnLoad()
SlashCmdList["MyAddon"] = MyAddon_SlashCommand;
    SlashCmdList["MyAddon"] = MyAddon_SlashCommand;
SLASH_MYADDON1= "/myaddon";
    SLASH_MYADDON1= "/myaddon";
this:RegisterEvent("VARIABLES_LOADED")
    this:RegisterEvent("VARIABLES_LOADED")
  end
  end


=== XML Files ===
=== XML Files ===
XML files are used to specify the visual style of your frames. More importantly though a frame allows you to easily pass events to your Lua files.  Check out [[XML User Interface]] for details. Here's a short example of an XML file:
XML files are used to specify the visual style of your frames. More importantly though a frame allows you to easily pass events to your Lua files.  Check out [[XML User Interface]] for details. Here's a short example of an XML file:


  <Script file="MyAddon.lua"/>  
  <Script file="MyAddon.lua"/>  
  <Frame name="MyAddon">  
  <Frame name="MyAddon">  
<Scripts>  
    <Scripts>  
<OnLoad>  
        <OnLoad>  
MyAddon_OnLoad();
            MyAddon_OnLoad();
</OnLoad>
        </OnLoad>
</Scripts>
    </Scripts>
  </Frame>
  </Frame>


== Start Coding! ==
== Start Coding! ==
Start with the tutorials extracted by the [http://us.blizzard.com/support/article.xml?locale=en_US&articleId=21466 Interface AddOn Kit]. The [[HOWTOs]] here has a ton of great examples to help you learn. Don't be shy to dig through someone else's AddOn for help, just be sure to not steal code, and give credit where credit is due.
Start with the tutorials extracted by the [http://us.blizzard.com/support/article.xml?locale=en_US&articleId=21466 Interface AddOn Kit]. The [[HOWTOs]] here has a ton of great examples to help you learn. Don't be shy to dig through someone else's AddOn for help, just be sure to not steal code, and give credit where credit is due.


== Slash Commands ==
== Slash Commands ==
A slash command is one way for the user to interact with your AddOn. These will be the easiest way for a beginner to let the user supply command and change options.
A slash command is one way for the user to interact with your AddOn. These will be the easiest way for a beginner to let the user supply command and change options.
The [[HOWTO: Create a Slash Command]] page covers this pretty well.
The [[HOWTO: Create a Slash Command]] page covers this pretty well.


== A Basic UI Frame ==
== A Basic UI Frame ==
The [[XML User Interface]] page covers a lot of a great basics.
The [[XML User Interface]] page covers a lot of a great basics.


== SavedVariables ==
== SavedVariables ==
The [[Saving variables between game sessions]] article covers the key points.  For folks new to AddOns but not other programming languages, just bear in mind that:
The [[Saving variables between game sessions]] article covers the key points.  For folks new to AddOns but not other programming languages, just bear in mind that:
* The SavedVariables is only read from on UI loading, not real time, and only saved to on UI unloading.  This will generally be from a user logging in or logging out.
* The SavedVariables is only read from on UI loading, not real time, and only saved to on UI unloading.  This will generally be from a user logging in or logging out.
Line 112: Line 115:


== Localization ==
== Localization ==
It's a good idea to plan from as early as possible to have your AddOn be localizable, even if you yourself only speak one language.  Review this great article for some things to think about: [[HOWTO: Localize an AddOn]].
It's a good idea to plan from as early as possible to have your AddOn be localizable, even if you yourself only speak one language.  Review this great article for some things to think about: [[HOWTO: Localize an AddOn]].
[[Category:HOWTOs|Get Started]]
[[Category:HOWTOs|Get Started]]