Thread Tools Display Modes
04-19-11, 06:34 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Problem with secure frame attributes

Hello,

I'm trying to bind a spell to middle click depending on player class from within the Factory function. Somehow it doesn't work. Here the code snippets:

lua Code:
  1. oUF:Factory(function(self)
  2.  
  3.     local playerClass = cfg.playerClass
  4.     local spellName
  5.    
  6.     if playerClass == "HUNTER" then
  7.          spellName = GetSpellInfo(34477)    -- Misdirection
  8.     elseif playerClass == "DRUID" then
  9.         spellName = GetSpellInfo(29166)     -- Innervate
  10.     elseif playerClass == "PALADIN" then
  11.         spellName = GetSpellInfo(31789)     -- Righteous Defense
  12.     elseif playerClass == "WARRIOR" then
  13.         spellName = GetSpellInfo(3411)      -- Intervene
  14.     elseif playerClass == "ROGUE" then
  15.         spellName = GetSpellInfo(57934)     -- Tricks of the Trade
  16.     elseif not spellName then
  17.         spellName = "Misdirection"
  18.     end
  19.  
  20.     self:SetActiveStyle("Rain")
  21.     self:Spawn("player", "oUF_Rain_Player"):SetPoint("CENTER", -210, -215)
  22.     self:Spawn("pet", "oUF_Rain_Pet"):SetPoint("BOTTOMLEFT", oUF_Rain_Player, "TOPLEFT", 0, 10)
  23.     self:Spawn("focus", "oUF_Rain_Focus"):SetPoint("BOTTOMRIGHT", oUF_Rain_Player, "TOPRIGHT", 0, 10)
  24.     self:Spawn("target", "oUF_Rain_Target"):SetPoint("CENTER", 210, -215)
  25.     self:Spawn("targettarget", "oUF_Rain_TargetTarget"):SetPoint("BOTTOMRIGHT", oUF_Rain_Target, "TOPRIGHT", 0, 10)
  26.     self:Spawn("focustarget", "oUF_Rain_FocusTarget"):SetPoint("BOTTOMLEFT", oUF_Rain_Target, "TOPLEFT", 0 , 10)
  27.    
  28.     if (cfg.showParty) then
  29.         local party = self:SpawnHeader(
  30.             "oUF_Rain_Party", nil, "solo,party,raid",
  31.             "showParty", true,
  32.             "showRaid", true,
  33.             "showPlayer", true,
  34.             "showSolo", true,
  35.             "maxColumns", 4,
  36.             "unitsPerColumn", 1,
  37.             "columnAnchorPoint", "LEFT",
  38.             "columnSpacing", 7.5,
  39.             "oUF-initialConfigFunction", ([[
  40.                 self:SetWidth(110)
  41.                 self:SetHeight(22)
  42.                 self:SetAttribute("type3", "spell")
  43.                 self:SetAttribute("spell3", %s)
  44.             ]]):format(spellName)
  45.         )
  46.         party:SetPoint("LEFT", UIParent, "BOTTOM", -231.25, 150)
  47.         party:Show()
  48.     end
  49. ...

I tested this on a druid, expecting to get Innervate or Misdirection if spellName and playerClass are not available. Instead I got nil. If I use self:SetAttribute("spell3", "Innervate") it works as expected. Is there an explanation for this? (Hopefully I typed it right )

I could also set the secure attributes from within the Shared function. Do I loose or gain something when doing so?

Thank you for your help
Rain
  Reply With Quote
04-20-11, 05:18 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Code:
self:SetAttribute("spell3", %s)
will be formatted as:
Code:
self:SetAttribute("spell3", Innervate)
(notice the lack of quotes. This is why it doesn't work.

Setting the attribute in the shared function would make it only work properly for frames created through :Spawn().
__________________
「貴方は1人じゃないよ」
  Reply With Quote
04-20-11, 06:15 PM   #3
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thank you, haste, it works now.

lua Code:
  1. self:SetAttribute("type3", "spell")
  2. self:SetAttribute("spell3", spellName)

at the beginning of Shared worked for all units, not only for those spawned by :Spawn()
  Reply With Quote
04-20-11, 06:23 PM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Rainrider View Post
Thank you, haste, it works now.

lua Code:
  1. self:SetAttribute("type3", "spell")
  2. self:SetAttribute("spell3", spellName)

at the beginning of Shared worked for all units, not only for those spawned by :Spawn()
Enter combat while header frames are created and execution will be stopped due to you calling a protected function in combat (:SetAttribute()).
__________________
「貴方は1人じゃないよ」
  Reply With Quote
04-21-11, 03:29 AM   #5
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Thank you again
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Problem with secure frame attributes


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