View Single Post
04-21-09, 10:42 AM   #1
Luzzifus
A Warpwood Thunder Caller
 
Luzzifus's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 94
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)
	return {	
		type = 'group', name = "Unit Name Settings", order = order, dialogHidden = true, dialogInline = true, 
		args = {
			playerPos	= {
				type = 'select',
				order = 8,
				name = unit,
				width = "half",
				values = { ["Top"] = "Top", ["Bottom"] = "Bottom", },
				get = function(info) return 
					nivcfgDB.names[unit].pos 
				end,
				set = function(info, value)	
					nivcfgDB.names[unit].pos = value
					oUF_Nivaya:UpdateNamePos(oUF.units[unit], unit)
				end, },
			
			...
		},
	}
end

function oUF_Nivaya:UpdateNamePos(self, unit)
	...
end
The important line is the red one. This function needs the stated parameters in order to apply the given settings to a specific frame. That architecture perfectly works as long as I am not in a party or a raid.

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')
Nedless to say that I need to call that for every unit everytime since I cannot restrict the call to a specific unit via the unit parameter. As a result this is destroying my dynamic architecture of the options table.

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.

Last edited by Luzzifus : 04-21-09 at 10:47 AM.
  Reply With Quote