Quantcast I need some help understanding how raid frame sorting works... - WoWInterface
Thread Tools Display Modes
08-17-13, 06:12 PM   #1
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
I need some help understanding how raid frame sorting works...

So I am making a simple addon to calculate the total amount of absorb heals currently on everyone in my raid. I have a separate frame for each raid member and anchored it to each raid member's unit frame.

Here is the problem:
I refer to each person in the raid group by UnitId that may or may not correspond to which position they occupy on default frames.

For example, Player A is occupying "raid6" (1st frame in group 2) on my raid frames (on default raid frames as well). However, it turns out Player A is the raid leader, so Player A's UnitId is "raid1". So if i update my addon for Player A, "raid1"'s frame is updated instead of "raid6". Domino effect -- "raid2" is now occupying "raid1" on my frames, etc...

Can someone shed some light on how to properly determine which frame I should update? Although Blizzard frames put Player A in its "raid6" (which is reflected in default raid frames after I move him there), his UnitId is still "raid1".

Any help is appreciated here. Thanks!
  Reply With Quote
08-17-13, 11:12 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The default raid frames can be sorted in several different ways, depending on the user's game settings. Fortunately, you don't actually need to worry about how they are sorted. The simplest solution would be to simply hook the function that each frame calls when it updates its own absorb display, and update your attached display frame at the same time:

Code:
hooksecurefunc("CompactUnitFrame_UpdateHealPrediction", function(frame)
	-- Find out which unit the frame is displaying:
	local unit = frame.displayedUnit

	-- Do stuff here.
end)
Without seeing your code, or even knowing what you're adding to the frames -- is it a texture? a font string? a status bar? something else? -- it's hard to give any more relevant suggestions, though.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
08-18-13, 12:01 AM   #3
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Thanks for the reply. I am completely new at using LUA so my code is a bit noobish. I am not hooking into my raid frames, but rather I have 10 separate frames, one on top of each unit frame to keep track of that player's buff.

So I start with XML UI frames:
Code:
<Button name="TotalAbsorbsR1" parent="UIParent" enableMouse="false" movable="false" frameStrata="MEDIUM">
		<Size x="50" y="10"/>
		<Anchors>
			<Anchor point="TOP" relativePoint="CENTER" relativeTo="ElvUF_Raid10Group1UnitButton1">
				<Offset x="-2" y="-5"/>
			</Anchor>
		</Anchors>
		<Layers>
			<Layer level="OVERLAY">
			<FontString name="$parentText" inherits="GameFontNormalSmall" justifyH="CENTER" setAllPoints="true" text=""/>
			</Layer>
		</Layers>
	</Button>
I made 10 of these and anchored each one (just a FontString) to each ElvUI raid frame.

Then, I have a list of frames that I made and a list of corresponding units

Code:
unitlist = {"target", "player", "raid1", "raid2", etc..}
buttonlist = {"TotalAbsorbsTar", "TotalAbsorbsSelf", "TotalAbsorbsR1", etc..}
Now on UNIT_AURA event trigger, I loop through all units from "unitlist" and update the FontString with the new value. So when I update "raid1", then "TotalAbsorbsR1" is updated with that value. (obviously this is inefficient, but right now I am just focused on fixing my current problem)

So when I am in a raid and I move, for example, the raid leader from group 1 to group 2, he is now associated with Group2Spot1 in my raid frames and "TotalAbsorbsR6" frame in my addon. Therefore, his UnitId should be "raid6". However, his UnitId is still "raid1". So now my addon will update unit "raid1" and post it to "TotalAbsorbsR1", which has a different person.

How can I check which unit is occupying a specific raid frame. Or if you have another suggestion, I would love to hear it.

Thank you for the help!
  Reply With Quote
08-18-13, 01:27 AM   #4
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Queue Phanx's "don't use XML" in 3.. 2.. 1..

As an aside, I wonder what it is that leads new addon developers to go the XML route so often.
  Reply With Quote
08-18-13, 01:38 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm guessing it's because there are so many ancient tutorials floating around from the early days that nobody has ever bothered to update, and the people reading them don't notice that the article was written before the release of TBC.

Anyway:

It would have been helpful for you to mention that you were working with ElvUI from the beginning. My post was written assuming you were working with the Blizzard raid frames, since your post only talked about those. As I have never used ElvUI or looked at its code, and have no interest in doing so, there's a lot less help I can offer on that front.

However, if you post your entire, actual code (seriously, why does nobody do this, even when explicitly asked to show their code???) instead of just some random snippets and vague descriptions of the code, I can probably solve your problem anyway... right now it looks like you're using a hardcoded list of units in a hardcoded order instead of actually looking at which units are being displayed on the frame.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
08-18-13, 02:25 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,115
Originally Posted by Phanx View Post
I'm guessing it's because there are so many ancient tutorials floating around from the early days that nobody has ever bothered to update, and the people reading them don't notice that the article was written before the release of TBC.
Or ancient addons that still might have some relevence were built on XML .
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 08-18-13 at 02:47 AM.
  Reply With Quote
08-18-13, 03:55 AM   #7
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Sorry, I didn't really bother including my entire code since it is so simple. Ignore everything commented out, I was just playing around with some code.

The addon actually works as intended unless for some reason unit "raidN" is not actually in Nth raid frame. I don't actually know how to inspect a raid frame to see which unit is occupying it.

Any help is appreciated, thanks!

Edit: Here is what my addon actually does/looks like. You can see the numbers on the raid frames on the bottom (e.g. +123.4k) and just overlays it on the frame.

Edit 2: Also I forgot to mention, it doesn't really matter what raid frames I am using; I am not touching raid frame code, and my raid frames have the same sorting as blizzard frames. This addon is pretty much separate and just sitting on top.
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_081813_050453.jpg
Views:	1273
Size:	1.94 MB
ID:	7811  
Attached Files
File Type: lua TotalAbsorbs.lua (3.6 KB, 116 views)
File Type: xml TotalAbsorbs.xml (8.1 KB, 125 views)

Last edited by nishay77 : 08-18-13 at 04:23 AM.
  Reply With Quote
08-18-13, 03:57 AM   #8
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Originally Posted by pelf View Post
Queue Phanx's "don't use XML" in 3.. 2.. 1..

As an aside, I wonder what it is that leads new addon developers to go the XML route so often.
I started learning WoW LUA from a WoW Programming book [World of Warcraft Programming (2nd Edition)]. In there, they say to use XML, but I honestly don't really see why. I need to switch everything to LUA to make it manageable.
  Reply With Quote
08-18-13, 06:04 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, ditch that book. Based on your code, I'd have to say that book is incredibly outdated, and is doing you a lot more harm than good.

Anyway, as suspected, the problem is that you are hardcoding your frames/units -- eg. you always attach your first frame to the first raid frame, and assume that corresponds to the "raid1" unit based on your hardcoded table of units. This assumption will nearly always be wrong. Instead, you should do several things:

(1) Parent your frames to the relevant raid frames instead of to the UIParent.

(2) When you update one of your frames, figure out which raid frame it's parented to, and then look at that frame to determine the unit. For default raid frames, the currently displayed unit is stored on the frame itself under the "displayedUnit" key as shown in my earlier post. For ElvUI frames, you'll have to figure it out yourself.

On a side note, there are a lot of other issues in your code:

(1) Currently you are putting your "unitlist" and "buttonlist" variables in the global scope. Don't do that. Make them local instead, as there is no need for them to be accessible outside of this file.

In cases where you do need variables to be global, give them names that are (a) unique and (b) clearly identify them as part of your addon, eg. "TotalAbsorbs_UnitList", but this is not one of those cases.

(2) Currently you are updating all frames whenever (a) any aura changes on any unit, including units who are not group members, (b) your target changes, or (c) any group roster change occurs. This is hugely wasteful, especially (a) which can fire hundreds of times per second in a raid combat situation.

Instead, since your addon is only concerned with absorption amounts, you should ignore all of those events, and just respond to UNIT_ABSORB_AMOUNT_CHANGED, which fires specifically to tell you about changes in the amount of absorption on a unit. When the event fires, you do not need to update every single frame -- only the one connected to that unit.

(3) Instead of looking at a few auras to figure out the amount of absorption, you should use the API functions that exist specifically to tell you how much absorption the unit has from all sources:

Code:
local amount = UnitGetTotalAbsorbs(unit)
(4) The table.getn function is deprecated. You should use the # operator instead:

Code:
for i = 1, #unitlist do
Even if it wasn't deprecated, it's still a function call, which is slow and should be avoided whenever possible.

There are a lot of other minor issues, but none of them are critical and will just distract you from the important issues. I'd suggest starting over using pure Lua, proper parenting, and the absorb-specific event and API as described above.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
08-18-13, 08:49 AM   #10
Cladhaire
Salad!
 
Cladhaire's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 1,935
Originally Posted by Phanx View Post
Yeah, ditch that book. Based on your code, I'd have to say that book is incredibly outdated, and is doing you a lot more harm than good.
Yeah, that's not a thing.
__________________
"There's only one thing that I know how to do well and I've often been told that you only can do what you know how to do well, and that's be you-- be what you're like-- be like yourself. And so I'm having a wonderful time, but I'd rather be whistling in the dark..."
  Reply With Quote
08-18-13, 03:48 PM   #11
nishay77
A Murloc Raider
Join Date: Aug 2013
Posts: 8
Ah, okay. Thanks for the help, I really appreciate it. I had no idea that API function existed. I'll give this a shot.
  Reply With Quote
08-18-13, 08:26 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Cladhaire View Post
Yeah, that's not a thing.
I know it's your book and all, but table.getn and XML for simple frames? That's pretty outdated stuff, and there's no reason a beginner should have to learn both Lua and XML in this day and age to make a simple addon. If you want to trade opinions about how well tutorials written in 2008 have aged, take it to PMs; there's no need to derail this thread.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
08-18-13, 08:28 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by nishay77 View Post
Ah, okay. Thanks for the help, I really appreciate it. I had no idea that API function existed. I'll give this a shot.
A good first step when writing an addon is to look at the code for any parts of the default UI that do something similar. That will give you an idea of what events and API functions you should be using. In this case, the default UI's raid frames show absorb amounts in some form, so CompactUnitFrame.lua should be on your reading list.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
08-18-13, 10:34 PM   #14
Cladhaire
Salad!
 
Cladhaire's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 1,935
Originally Posted by Phanx View Post
I know it's your book and all, but table.getn and XML for simple frames? That's pretty outdated stuff, and there's no reason a beginner should have to learn both Lua and XML in this day and age to make a simple addon. If you want to trade opinions about how well tutorials written in 2008 have aged, take it to PMs; there's no need to derail this thread.
And that's your problem, you haven't read the book and you just blindly assumed that I would have been writing table.getn in 2007 and 2009. That isn't the case.. I didn't write the code that was posted above and its not fair or reasonable of you to assume that its solely the result of the book.

We can disagree about Lua vs. XML all you want, but I've been an educator for 10 years and I stand by the pedagogical style, progression, and path that I use in BOTH of the books. The second edition I am particularly proud of because of the refinements I was able to make on it. I use both XML and Lua to great effect and with the correct separation of concerns.

The book isn't the issue here, perhaps next time you could help someone without casting aspersions on something its clear you don't know much about.
__________________
"There's only one thing that I know how to do well and I've often been told that you only can do what you know how to do well, and that's be you-- be what you're like-- be like yourself. And so I'm having a wonderful time, but I'd rather be whistling in the dark..."
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » I need some help understanding how raid frame sorting works...

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