Thread Tools Display Modes
12-18-09, 06:34 AM   #1
Nodd
A Murloc Raider
 
Nodd's Avatar
Join Date: Dec 2009
Posts: 7
Auras sorting

I'm trying to implement a very custom sorting for my auras.
I want auras casted by me first, with priority on some auras, the others being sorted by decreasing total time. Here's what I've done so far :

Code:
local AuraPrio = { 139 }

local function AuraSort(a,b)
	if not a then
		return false
	elseif not b then
		return true
	elseif a.caster=='player' and not(b.caster=='player') then
		return true
	elseif b.caster=='player' and not(a.caster=='player') then
		return false
	elseif a.caster=='player' and b.caster=='player' then
		for i,Id in ipairs(AuraPrio) do
			if a.Id==Id then
				return true
			elseif b.Id==Id then
				return false
			end
		end
	end

	return a.duration >= b.duration
end

local function preAuraSetPosition(self,aura,max)
	for i=1, max do
		if aura[i] then
			local auras = aura[i]:GetParent()
			local frame = auras:GetParent()
			local unit, filter = frame.unit, auras.filter
			_, _, _, _, _, aura[i].duration, _, aura[i].caster, _, _,aura[i].Id = UnitAura(unit, i, filter)
		
			if( aura[i].duration == nil ) then
				aura[i].duration = math.huge
			end
		end
	end

	table.sort(aura,AuraSort)
end
But when an aura expires, I get an error : "attempt to index local value 'b' (a userdata value)" at the second "elseif" in function "AuraSort".

It works fine if I set the sorting function to :
Code:
local sort = function(a, b)
	return a.duration > b.duration
end
Any ideas ?

Bonus question :
in preAuraSetPosition, the for loop should go to 'max' ou '#aura' ?
  Reply With Quote
12-21-09, 05:54 PM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Nodd View Post
Bonus question :
in preAuraSetPosition, the for loop should go to 'max' ou '#aura' ?
Bonus answer:
Pre-sort: Going to max is in most cases enough.
Post-sort: Going to #auras is the only certain solution.

Commit f91cf5fc should be enough to explain why this is.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-23-09, 04:49 AM   #3
Nodd
A Murloc Raider
 
Nodd's Avatar
Join Date: Dec 2009
Posts: 7
Thanks Haste !

Code:
if not a then
became
Code:
if (not a) or (not a:IsShown())  then
And everything works like a charm !


I'm a bit afraid of "in most cases enough". Does it means I should go to #auras to be certain ?

The table.sort function enables to limit the range of the table which will be sorted. (http://lua-users.org/wiki/TableLibraryTutorial)
Setting
Code:
auras.n = max
would be "in most cases enough" then ?
  Reply With Quote
12-23-09, 05:13 AM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Nodd View Post
Thanks Haste !
I'm a bit afraid of "in most cases enough". Does it means I should go to #auras to be certain ?
You should only have to go to #auras if your artificially injecting auras into the table.
Originally Posted by Nodd View Post
The table.sort function enables to limit the range of the table which will be sorted. (http://lua-users.org/wiki/TableLibraryTutorial)
Setting
Code:
auras.n = max
would be "in most cases enough" then ?
That's the Lua 5.0 behavior. It won't work in Lua 5.1.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-23-09, 09:38 AM   #5
Nodd
A Murloc Raider
 
Nodd's Avatar
Join Date: Dec 2009
Posts: 7
Oops, I wrote too fast : I still get the "attempt to index local value 'b' (a userdata value)".
It seems logical actually : 'b:IsShown' isn't valid if 'b' is not valid either.

I get it sometimes when a buff fades (but not everytime).
  Reply With Quote
06-15-10, 02:43 PM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
it should work fine, no real changes has been made to sorting since around 1.3.20 or so. I'd just suggest debugging it and see if you can figure out why it fails (and how).
__________________
「貴方は1人じゃないよ」
  Reply With Quote
06-15-10, 03:08 PM   #7
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
Necro Haste!

On a serious matter I just deleted the posts because I figured out what was wrong after.
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.
  Reply With Quote
06-15-10, 03:10 PM   #8
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by v6o View Post
Necro Haste!

On a serious matter I just deleted the posts because I figured out what was wrong after.
I saw you deleted it the first time at least :P
__________________
「貴方は1人じゃないよ」
  Reply With Quote
06-27-10, 05:57 AM   #9
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
I figured there was no need for a new topic about this so i'm dropping this here.

I'm not as complicated, i only wanted a simple duration sorting for my buffs/debuffs, and using:

Code:
local SortAura = function(a, b)
	return (a.timeLeft) > (b.timeLeft)
end

local PreSetPosition = function(auras)
	sort(auras, SortAura)
end
With the player frame it's just fine, but with the target frame (and some others aswell), the timers seems "jumpy", and i can't figure out why.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }

Last edited by Caellian : 06-27-10 at 06:32 AM.
  Reply With Quote
06-27-10, 11:56 AM   #10
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Make sure the .timeLeft attribute is on all the icons, and that they are set before the sort function triggers.

I set the .timeLeft in CustomFilter, you can take a look at how I did it:
http://github.com/p3lim/Scent/blob/master/Auras.lua
  Reply With Quote
06-27-10, 08:13 PM   #11
Caellian
A Frostmaul Preserver
 
Caellian's Avatar
Join Date: May 2006
Posts: 281
Originally Posted by p3lim View Post
Make sure the .timeLeft attribute is on all the icons, and that they are set before the sort function triggers.

I set the .timeLeft in CustomFilter, you can take a look at how I did it:
http://github.com/p3lim/Scent/blob/master/Auras.lua
Very nice, thanks, it worked.
__________________
if (sizeof(workload) > sizeof(brain_capacity)) { die('System Overload'); }
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Auras sorting


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