Reliably referencing the player frame
Hi,
this is an issue I've run into a few times now, so the code I'm posting here is only an example. So as an example, in my layouts config I am building some dynamic option frames to adjust the unit names for different units. That looks something like this: Code:
local optUnitNames = function(order, unit) In a party or a raid, my layout also shows the player as a unit button in the raidframes. When the above update function is now called for the player frame, I'm getting an error about unit being nil in UpdateNamePos(). For some reason, oUF references the unit button in the raidframes instead of the actual player frame via oUF.units['player']. I managed to work around that via adding global references to the spawned frames, like this: Code:
oUF_Nivaya:UpdateNamePos(oUF_player, 'player') So, is there a way to reliably reference the player frame via a units parameter and without using a global reference? Thanks in advance, Luzzifus. |
You could always iterate over oUF.objects and check if the unit is player, and run your code if it is. oUF.units is really just meant for quick unreliable indexing.
|
Iterating through all units for every call doesn't look too efficient, does it?
There's something else crossing my mind given my global reference, how about this: Code:
local v = _G['oUF_'..unit] **edit: Btw. what's the exact difference between oUF.units, oUF.objects and oUF.elements? |
The iterators in Lua aren't exactly slow, and you are most likely not calling them all the time anyway. You can ofc. use a global, it's all up to you really :).
oUF.objects - Contains every frame touched by oUF. oUF.units - Contains all the units that oUF knows about. The list is created by watching what gets sent to :SetAttribute('unit', ...). oUF.elements - Doesn't exist. You might be thinking of the __elements table that exists on oUF objets however. This table just contains all the active elements on a frame. |
Thanks alot, that will help. :)
|
i got around this by creating a units table on my addon object.
http://github.com/airtonix/oufsmee2/...e.lua#L966-988 oUF_Smee2.units is a table built off my settings table. This way i can interate over the exact frames i create. I do the same thing in my raid layout : Code:
local raidSettings = db.frames.raid |
All times are GMT -6. The time now is 11:53 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI