Thread Tools Display Modes
08-15-14, 07:29 AM   #21
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
sure okay, that makes sense. I think I was having issues because i'd swapped a few things round to get it working before (note: not the version i'm using now):

Lua Code:
  1. --
  2. --
  3.  
  4.     local fontstring = frame:CreateFontString(nil, "ARTWORK")
  5.     local fontstrings = {}
  6.    
  7.     frame:SetScript("OnEvent", function(self, event, ...)        
  8.         local shown = 0
  9.        
  10.         -- hide any unused ones first
  11.         for i = shown + 1, #fontstrings do
  12.             fontstrings[i]:Hide()
  13.         end
  14.        
  15.         for i = 1, #cfg.spells do
  16.             local spell = cfg.spells[i]
  17.             local _, _, _, stacks = UnitBuff("player", spell.name)
  18.             if stacks and spell.show==true then
  19.                
  20.                 shown = shown + 1
  21.                 local fontstring = frame:CreateFontString(nil, "ARTWORK")
  22.                 fontstrings[shown] = fontstring -- keep them all in another indexed table
  23.                 fontstring:SetFont(STANDARD_TEXT_FONT, spell.size, "OUTLINE")
  24.                 fontstring:SetShadowOffset(0, 0)
  25.                 fontstring:SetText(string.rep(spell.symbol, stacks > 0 and stacks or 1))
  26.                 fontstring:SetTextColor(spell.colour[1], spell.colour[2], spell.colour[3])
  27.                 fontstring:ClearAllPoints()
  28.                 if shown > 1 then
  29.                     fontstring:SetPoint("BOTTOMRIGHT", fontstrings[shown - 1], "TOPRIGHT", 0, -5)
  30.                 else
  31.                     fontstring:SetPoint("RIGHT", UIParent, "CENTER", 96, 75)
  32.                 end
  33.                 fontstring:SetJustifyH("RIGHT")
  34.                 fontstring:SetSpacing(2)
  35.                 fontstring:Show()
  36.             end
  37.         end
  38.     end)
  39. --
  40. --

Anyway, i've just tried this new method. Here's the full code:

https://gist.github.com/anonymous/1bcb3a092180fa6cf71b

Getting:

Code:
1x SpellActivationOverlay.lua:43: attempt to index global "fontstrings" (a nil value)
whenever more than one string tries to show.

Last edited by ObbleYeah : 08-15-14 at 07:34 AM.
  Reply With Quote
08-15-14, 08:35 AM   #22
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
fixed. swapped

Lua Code:
  1. line:SetPoint("BOTTOMRIGHT", fontstrings[i-1], "TOPRIGHT", 0, -5)

for

Lua Code:
  1. line:SetPoint("BOTTOMRIGHT", t[i-1], "TOPRIGHT", 0, -5)
  Reply With Quote
08-16-14, 01:18 AM   #23
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Code:
    -- namespace
    local _, ns = ...
    local cfg = ns
If you want to refer to your private table as "cfg" instead of "ns" just name it that in the first place:

Code:
    -- namespace
    local _, cfg = ...
There's nothing forcing you to use "ns" or any other particular variable name here. It's just a standard variable assignment, so you can use whatever variable names you want.

Code:
fontstring:SetShadowOffset(0, 0)
Since this never changes, you should just do it when you create the font string, not every time you update it.

Code:
        -- hide any unused ones first
        for i = shown + 1, #fontstrings do
            fontstrings[i]:Hide()
        end
You should do this after you've looped over the spells -- where it's placed now, shown is still 0, so you're just wasting CPU cycles hiding font strings you're just going to show again 5 lines down.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-03-14, 03:44 AM   #24
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
Hello, bumping this up because i'm getting a new error in the latest beta build related to this code:

Code:
1x spellactivationoverlay.lua:29: attempt to compare string with nil
Relevant code here: https://gist.github.com/anonymous/483fc65cde3339f6ab8c

I'm assuming it's to do with the recent GetSpellInfo() change:

Originally Posted by p3lim
No changes in build 18738, but GetSpellInfo no longer returns empty strings on invalid parameters, now returns nil as intended.
but not sure how to modify what I have to handle that - some kind of check for if spell.name is returning nil or not somewhere?
  Reply With Quote
09-03-14, 04:38 AM   #25
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Ehm ... line 29 states "end".
  Reply With Quote
09-03-14, 05:13 AM   #26
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Since line 1 is blank I assume everything just got shifted down by 1 line when you pasted, and the error is coming from this:

Code:
return a.priority < b.priority or a.priority==b.priority and a.name < b.name
If you're sure all the subtables in your spells table have a priority key, then the issue is probably with spells that don't exist anymore (or yet). I'd just remove them from the table in the previous block:

Code:
    -- get info
    for i = #cfg.spells, 1, -1 do
        local spell = cfg.spells[i]
        spell.name = GetSpellInfo(spell.id)
        if not spell.name then
            print("Spell", spell.id, "doesn't exist!")
            tremove(cfg.spells, i)
        end
    end
Note the reversed iteration order for the loop; this is important since otherwise removing indices inside the loop will cause some entries to be skipped as the indices shift.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
09-03-14, 05:55 AM   #27
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
oops, yep - dodgy copy paste. Sorry.

Perfect, thanks - it appears that hunter's "lock & load" spellID has been changed.
  Reply With Quote
09-03-14, 05:36 PM   #28
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If this is something you're planning to release, you should probably also include some basic sanity checks in that loop, to account for users who try to add spells but don't really know what they're doing:

Code:
    -- get info
    for i = #cfg.spells, 1, -1 do
        local spell = cfg.spells[i]
        if not spell.id then
            print("Missing spell ID in entry", i, " -- please check your data!")
        else
            if not spell.priority then
                spell.priority = 1 -- change this to whatever default you want to use
            end
            spell.name = GetSpellInfo(spell.id)
            if not spell.name then
                print("Spell", spell.id, "doesn't exist!")
                tremove(cfg.spells, i)
            end
        end
    end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » checking for buff stacks in C_L_E_U

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