Reply
Thread Tools Display Modes
Unread 03-26-13, 10:54 AM   #1
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 318
Warlock resources bar problem

Here is my try at the warlock resources bar: https://gist.github.com/Rainrider/5246884

However, when testing this on a toon that does not have the prereq spells, I get the following error:

oUF: Error: Style [Rain] attempted to register event [SPELLS_CHANGED] on unit [player] with a handler that doesn't exist.
I checked Phanx' code as a reference and it seems to me (s)he does the same thing: registers the handler for the event from within the handler, but does not have any errors.

Could someone explain the difference I fail to see please?
Rainrider is offline   Reply With Quote
Unread 03-26-13, 11:02 PM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,591
That error means that you wrote the wrong function name in your RegisterEvent call, or have a scoping issue. To avoid scoping issues, I usually define all my function names first, and then the functions:

Code:
local Visibility, Update, Path, ForceUpdate, Enable, Disable

function Visibility(self, event)
    -- stuff
end

function Update(self, event)
    -- stuff
end

-- etc
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 03-27-13, 08:13 AM   #3
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 318
Thanks for the reply Phanx. Upvaluing Visibility solved it. The other way was using
Code:
local function Visibility(self)
instead of
Code:
local Visibility = function(self)
I thought the first one is just syntactic sugar for the second, but apparently it's not just that. Could someone please explain that?
Rainrider is offline   Reply With Quote
Unread 03-27-13, 02:10 PM   #4
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,591
It's slightly different. There's a post somewhere on WowAce where someone explained it in a bit more detail, but basically "local function x() end" works like "make a function named x, and then make it local" while "local x = function() end" works like "make a function, and then assign it to the local variable x"... it's executed from right to left, so with the latter, the function is defined first, and then the variable, so if you try to call "x" from inside the function, the "local x" part hasn't been defined yet, and you're looking for a global "x" which probably doesn't exist, and won't be what you want even if it does.

Code:
local function print(x)
    UIErrorsFrame:AddMessage(x)
    if x == "Hello" then
        print("Hello to you too")
    end
end
print("Hello")
^ The inner "print" refers to the "local function print", so both messages go to the UIErrorsFrame.

Code:
local print = function(x)
    UIErrorsFrame:AddMessage(x)
    if x == "Hello" then
        print("Hello to you too")
    end
end
print("Hello")
^ The inner "print" refers to the global "print", so "Hello" goes to the UIErrorsFrame, but "Hello to you too" goes to the DEFAULT_CHAT_FRAME.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 03-28-13, 07:00 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 982
Lua Code:
  1. local function func() end
  2. -- is sugar for:
  3. local func;
  4. func = function() end
  5.  
  6. -- Also note that:
  7. local func = function()
  8.    print(func) -- prints nil
  9. end
  10. local function func()
  11.    print(func) -- funcction: 0xHEX
  12. end
__________________
「貴方は1人じゃないよ」
haste is offline   Reply With Quote
Reply

Go BackWoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Warlock resources bar problem

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