Thread Tools Display Modes
04-29-11, 07:58 PM   #1
Maliack
A Defias Bandit
Join Date: Apr 2011
Posts: 2
sTotal noob question

Hi all,

I'm having some difficulties getting into writing an addon. It seems that the APIs aren't really documented in any one place - I've tried wowprogramming, wowhead, wowwiki, and just not sure if there's a 'definitive' description available.

I'm trying to get past the "Hello, world" coding, and just get something as simple as the current player's mana, etc.

I try something like:

Code:
  local powerType, powerToken = UnitPowerType("player");
  print("powerToken is = ".. powerToken);
  print("powerType is = ".. powerType);
So, on my Shaman (resto), I get that powerToken = "" and powerType = 0 (so, mana).

If I try calling and then printing the value of UnitPower("player"), I always end up with 0 being output.

I'm not sure if I'm missing something very obvious, or what. If anyone has some suggestions, or even a helpful smack upside the head, I'd appreciate it!
  Reply With Quote
04-29-11, 11:38 PM   #2
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,364
Maybe this will help a little: WoWPedia: Interface Customization Portal
  Reply With Quote
04-29-11, 11:44 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The API is as fully documented as it can get, being put there and updated only by authors like us. I use wowpedia and wowprogramming, myself.


If you are looking for information on the Lua language itself, then you need to go to lua.org and read through the PIL: http://www.lua.org/manual/5.1/
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
04-30-11, 02:51 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
The WoW API tries to run in an object-oriented approach, in which UI objects generate events to be handled by registered functions called handlers. Frame events will be called by this name to differentiate from data events that fire through the "OnEvent" handler. It is common for data functions in the WoW API to not have valid data until after a specific event related to the function has fired.

In this example, we'll have the code wait until after the PLAYER_LOGIN event fires before printing out our info.
lua Code:
  1. local frame=CreateFrame("Frame");-- Create our frame
  2. frame:RegisterEvent("PLAYER_LOGIN");--  Register to listen for PLAYER_LOGIN
  3. frame:SetScript("OnEvent",function(self,event,...)--    Register an OnEvent handler
  4. --  OnEvent supplies the following in this order:
  5. --      self    Pointer to the frame
  6. --      event   The name of the data event firing
  7. --      ...     Vararg list related to the data event
  8.  
  9. --  Check for the correct event
  10. --  It's good practice to check the event being fired in case you want to add more events to be handled
  11.     if event=="PLAYER_LOGIN" then
  12. --      Grab our power type and print it out
  13.         local ptype,ptoken=UnitPowerType("player");
  14.         print("Token:",ptoken);
  15.         print("TypeID:",ptype);
  16.     end
  17. end);

Information is only as good as a person's understanding of it.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
04-30-11, 05:52 PM   #5
Maliack
A Defias Bandit
Join Date: Apr 2011
Posts: 2
Hey there,

Thanks very much for your responses - I appreciate it!

I understood that the functions are executed based on events (which your addon needs to register for). I just had my function get called when the "OnLoad" event happened. I was just surprised when 0 was always returned by the UnitPower() calls.

I'll keep poking around and looking at more examples, and at the sites that you listed.

Thanks again!
  Reply With Quote
04-30-11, 07:18 PM   #6
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
Originally Posted by Maliack View Post
Hey there,

Thanks very much for your responses - I appreciate it!

I understood that the functions are executed based on events (which your addon needs to register for). I just had my function get called when the "OnLoad" event happened. I was just surprised when 0 was always returned by the UnitPower() calls.

I'll keep poking around and looking at more examples, and at the sites that you listed.

Thanks again!
Well actually OnLoad gets called when your addon gets fully loaded, not when the UI is ready (Or OnLoad might actually just be called when the frame is loaded, and ADDON_LOADED when the addon is loaded, but im pretty sure its when your addon gets fully loaded)

either way, OnLoad doesnt refer to the client or the game as being loaded, just your addon.

http://www.wowpedia.org/Events_that_...oading_Process

Try using wowpedia.org over wowwiki... wowwiki moved to wowpedia when the hosting wiki site overloaded the site with ads and forced a certain formatting style to non registered users, which was some white thingy, and a lot of people didnt like that.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » sTotal noob question

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