WoW Frames Tutorial

To understand Frames, i've created a little Addon for myself, to learn how these things are working.
Learning Lua was easy, but the XML Frames are a bit more of a challenge because there is no 100% documentation on it.
So the easiest way to learn is to start an Addon to play around with it.

To start the Tutorial we need the folder \Interface\Addons\FaraFrames\ , where we have 3 basic files:

FaraFrames.toc
## Interface: 1600
## Author: Farang
## Title: FaraFrames
## Notes: FaraFrames - XML Frame Examples
## Version : 1.0
FaraFrames1.xml

FaraFrames1.XML, here the basic setup:

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
  <Script file="FaraFrames.lua"/>
  <!-- Here the Scripts that have to be Executed -->
  <Frame name="FaraFrames_GeneralScripts" hidden="true">
  <Scripts>     <OnLoad> FaraFrames_OnLoad(); </OnLoad></Scripts>
  </Frame> 
</Ui>
 

We use here our first Frame FaraFrames_GeneralScripts,
just to have the OnLoad Procedure just once (this is a special setup for this test addon),
it's not necessary for your own addons.

The corresponding Function inside FaraFrames.lua:

function FaraFrames_OnLoad()
  out("FaraFrames: OnLoad");
  SLASH_FARAFRAMES1 = "/faraframes";
  SLASH_FARAFRAMES2 = "/ff";
  SlashCmdList["FARAFRAMES"] = function(msg)
		FaraFrames_SlashCommandHandler(msg);
	end
end
 


We take a look at what else is needed inside FaraFrames.lua

function out(text)
 DEFAULT_CHAT_FRAME:AddMessage(text)
 UIErrorsFrame:AddMessage(text, 1.0, 1.0, 0, 1, 10) 
end

the out function is simply used to print out information ,in the chat frame and on the screen top center.

Also we need a SlashCommandHandler function we already set it in the OnLoad function, here it is:

function FaraFrames_SlashCommandHandler(msg)
    out("FaraFrames: " .. msg)
	if (msg == "0") then
	 ReloadUI();
	end
 	FaraFrames_Toggle(msg);
end


Now we can use this Addon in game, with /ff. While we can already Reload the UI (this means it will refresh all scripts) with /ff 0
We can't open any frame yet, because we haven't done one yet. Later on we can call our first frame with /ff 1 and so on..

Before we do that we need to complete our Lua file with the function FaraFrames_Toggle() which is used to show/hide the frames

 
function FaraFrames_Toggle(num)
   local frame = getglobal("FaraFrames" .. num)
   if (frame) then
   if(  frame:IsVisible() ) then
      frame:Hide();
   else
      frame:Show();
   end
   end
end



We have our first working version of FaraFrames.lua togehter, you can see the complete source here

Let's continue, we will now create our first Frame
Proceed to Frame 1