WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Auras.PostCreateIcon? (https://www.wowinterface.com/forums/showthread.php?t=55903)

Naisz 12-06-17 11:35 AM

Auras.PostCreateIcon?
 
Hello folks!

At first id like to thank everyone for the initial help they gave me on here. My layout is coming together the way i want to. But sadly im running into a Problem again with displaying Auras, or rather setting the TexCoord of the related icon.

this is located inside another .lua file
Lua Code:
  1. local _,ns = ...
  2.  
  3. [-unrelated code-]
  4.  
  5. ns:UpdateAuraIcon = function(element, button)
  6.          button.overlay:SetAlpha(0)
  7.          button.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
  8.      button.icon:SetDrawLayer('ARTWORK')
  9. end

inside my Layout file im doing
Lua Code:
  1. local Auras = CreateFrame('Frame', nil, self)
  2.                 Auras.gap = true
  3.                 Auras.size = 20
  4.                 Auras:SetHeight(60)
  5.                 Auras:SetWidth(200)
  6.                 Auras:SetPoint('BOTTOMLEFT', self.Health, 'TOPLEFT', 0, 0)
  7.                 Auras.initialAnchor = 'BOTTOMLEFT'
  8.                 Auras['growth-x'] = 'RIGHT'
  9.                 Auras['growth-y'] = 'UP'
  10.                 Auras.numBuffs = cfg.numBuffs
  11.                 Auras.numDebuffs = cfg.numDebuffs
  12.                 Auras.spacing = 1
  13.                 Auras.showStealableBuffs = true
  14.  
  15.                 Auras.PostCreateIcon = ns.UpdateAuraIcon
  16.                 Auras.PostUpdateIcon = ns.PostUpdateIcon
  17.                 self.Auras = Auras

For some reason, ns.UpdateAuraIcon doesnt trigger as far as i experienced

Other stuff inside the namespace, for example cfg.numBuffs is working fine. But it feels like it isnt triggering the function outside the .lua-file but inside the namespace? Am i doing something wrong regarding functions inside the namespace?

Thanks in advance and greetings!

EDIT:

I solved the issue by doing

lua Code:
  1. function ns:UpdateAuraIcon(button)

i dont know why the other option didnt work, if someone knows. please feel free to explain :)

haste 12-06-17 01:21 PM

Code:

ns:UpdateAuraIcon = function(element, button)
Isn't valid Lua, so that's why it didn't work. It should be:
Code:

ns.UpdateAuraIcon = function(element, button)
Notice the dot instead of semi-colon

Your new function definition works because:
Code:

function ns:UpdateAuraIcon(button)
Is the same as:
Code:

function ns.UpdateAuraIcon(ns, button)

Naisz 12-06-17 03:51 PM

Okay thanks :)

I thought that the colon is referring to functions, like when setting Properties or Textures on specific frames.
But i guess, that ns.<functionname> then refers to the name of the function inside the namespace rather than a function inside the namespace.

Thanks alot haste!

Kanegasi 12-06-17 04:04 PM

The colon in Lua is essentially shorthand for passing "self", or "this" as it used to be called. When using the colon, you're telling the function you're calling to automatically accept the object before the colon as the first argument. Without the colon, you're just calling the function itself. The dot is irrelevant here, it's just a way to access the function within the table. This can be confusing at times due to WoW's frame objects and the inherit functions that live in a frame's table.

Adding to the last function example of Haste's reply, this is also the same:

Code:

function ns["UpdateAuraIcon"](ns, button)

haste 12-07-17 03:27 AM

Quote:

Originally Posted by Naisz (Post 326039)
But i guess, that ns.<functionname> then refers to the name of the function inside the namespace rather than a function inside the namespace.

No, function tbl:func() is just syntactic sugar for tbl.func = function(self). Just like calling tbl:func() is syntactic sugar for tbl.func(tbl). You can read more about Lua's function definitions here.

Quote:

Originally Posted by Kanegasi (Post 326040)
Code:

function ns["UpdateAuraIcon"](ns, button)

That's not valid Lua, unless you meant to call the function. In that case you have to remove function from the line.


All times are GMT -6. The time now is 05:31 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI