Thread Tools Display Modes
11-21-13, 02:39 PM   #1
Dralie
A Defias Bandit
Join Date: Nov 2013
Posts: 3
Issues with Textures

Hello I am trying to make a simple addon that makes a box and has it change colors based on what type of stagger you have on a brewmaster monk. I have run into an issue where the box is no longer showing up and doesnt change textures when I get it to show up.

Lua Code:
  1. local StaggerBox = CreateFrame("Frame",nil,UIParent)
  2. StaggerBox:SetFrameStrata("BACKGROUND")
  3. StaggerBox:SetWidth(64) -- Set these to whatever height/width is needed
  4. StaggerBox:SetHeight(64) -- for your Texture
  5. StaggerBox:SetPoint("CENTER",-150,0)
  6. StaggerBox:RegisterEvent("PLAYER_REGEN_DISABLED")
  7. StaggerBox:RegisterEvent("PLAYER_REGEN_ENABLED")
  8. StaggerBox:CreateTexture()
  9. StaggerBox:SetAllPoints()
  10. local function HideOrShow(self, event, ...)
  11.     if event == "PLAYER_REGEN_DISABLED" then
  12.         StaggerBox:Show()
  13.    
  14.     elseif event == "PLAYER_REGEN_ENABLED" then
  15.         StaggerBox:Hide()
  16.         end
  17. end
  18.  
  19. StaggerBox:SetScript("OnEvent", HideOrShow)
  20.  
  21.  
  22. local function DebuffCheck(self, event, ...)
  23.     if UnitDebuff("player","Light Stagger") then
  24.         StaggerBox:SetTexture(.5,1,0,1)
  25.     elseif UnitDebuff("player","Medium Stagger") then
  26.         StaggerBox:SetTexture(.5,1,0,1)
  27.     elseif UnitDebuff("player","Heavy Stagger") then
  28.         StaggerBox:SetTexture(1,0,01)
  29.     end
  30. end
  31.  
  32. StaggerBox:SetScript("OnEvent", DebuffCheck)
  Reply With Quote
11-21-13, 02:47 PM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
StaggerBox:SetScript("OnEvent", DebuffCheck) is overwriting your first event handler.

You either need to register the UNIT_AURA event and check your debuffs when that fires or make it an OnUpdate script since UNIT_AURA could very well fire more often than once per frame if you're in a group.
  Reply With Quote
11-21-13, 03:13 PM   #3
Dralie
A Defias Bandit
Join Date: Nov 2013
Posts: 3
The error I get before and after the changes you suggested is showing
Code:
Message: Interface\AddOns\Stagger\Stagger.lua:24: attempt to call method 'SetTexture' (a nil value)
Time: 11/21/13 15:07:34
Count: 2010
Stack: [C]: in function `SetTexture'
Interface\AddOns\Stagger\Stagger.lua:24: in function <Interface\AddOns\Stagger\Stagger.lua:22>
  Reply With Quote
11-21-13, 03:32 PM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Dralie View Post
The error I get before and after the changes you suggested is showing
Code:
Message: Interface\AddOns\Stagger\Stagger.lua:24: attempt to call method 'SetTexture' (a nil value)
Time: 11/21/13 15:07:34
Count: 2010
Stack: [C]: in function `SetTexture'
Interface\AddOns\Stagger\Stagger.lua:24: in function <Interface\AddOns\Stagger\Stagger.lua:22>
StaggerBox is a frame not a texture, first you need to put a texture on that frame prolly something white because you can color that nicely (texture:SetTexture("Interface\\Buttons\\White8x8.blp"), then color it with texture:SetVertexColor(r, g, b).

Last edited by Resike : 11-21-13 at 03:46 PM.
  Reply With Quote
11-21-13, 03:44 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Something like that:

Lua Code:
  1. local StaggerBoxFrame = CreateFrame("Frame", nil, UIParent)
  2. StaggerBoxFrame:SetFrameStrata("Background")
  3. StaggerBoxFrame:SetWidth(64)
  4. StaggerBoxFrame:SetHeight(64)
  5. StaggerBoxFrame:SetPoint("CENTER", - 150, 0)
  6. StaggerBoxFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
  7. StaggerBoxFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
  8. StaggerBoxFrame:RegisterEvent("UNIT_AURA")
  9.  
  10. local StaggerBox = StaggerBoxFrame:CreateTexture(nil, "Background")
  11. StaggerBox:SetTexture("Interface\\Buttons\\White8x8.blp")
  12. StaggerBox:SetDrawLayer("Background", 0)
  13. StaggerBox:SetAllPoints(StaggerBoxFrame)
  14.  
  15. local function OnEvent(self, event, ...)
  16.     if event == "PLAYER_REGEN_DISABLED" then
  17.         StaggerBox:Show()
  18.     elseif event == "PLAYER_REGEN_ENABLED" then
  19.         StaggerBox:Hide()
  20.     elseif event == "UNIT_AURA" then
  21.         local unit = ...
  22.         if unit == "player" then
  23.             if UnitDebuff("player", "Light Stagger") then
  24.                 StaggerBox:SetVertexColor(0.5, 1, 0, 1)
  25.             elseif UnitDebuff("player", "Medium Stagger") then
  26.                 StaggerBox:SetVertexColor(0.5, 1, 0, 1)
  27.             elseif UnitDebuff("player", "Heavy Stagger") then
  28.                 StaggerBox:SetVertexColor(1, 0, 0, 1)
  29.             end
  30.         end
  31.     end
  32. end
  33.  
  34. StaggerBoxFrame:SetScript("OnEvent", OnEvent)

Last edited by Resike : 11-21-13 at 03:48 PM.
  Reply With Quote
11-21-13, 04:09 PM   #6
Dralie
A Defias Bandit
Join Date: Nov 2013
Posts: 3
Edit: I realized what I messed up
Thank you very much for your help!

Last edited by Dralie : 11-21-13 at 04:16 PM.
  Reply With Quote
11-21-13, 04:17 PM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Dralie View Post
Edit: I realized what I messed up
Thank you very much for your help!
No problem.
  Reply With Quote
11-21-13, 05:17 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Just FYI, if all you want is a solid color for your texture, you don't need to give it a texture file first and call :SetVertexColor(). You can just use :SetTexture(r,g,b[,alpha])
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
11-22-13, 01:44 AM   #9
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
What Seerah wrote is true but I have to say that at some point I had errors with just using SetTexture because doing this:
Lua Code:
  1. local tex:CreateTexture(nil,"BACKGROUND",nil,-8)
  2. tex:SetTexture(1,0,0,0.5)
would not give me a red semi-transparent texture. It may be fixed now but I definitely had it happening.

Combining both works perfectly anytime:
Lua Code:
  1. local tex:CreateTexture(nil,"BACKGROUND",nil,-8)
  2. tex:SetTexture(1,1,1)
  3. tex:SetVertexColor(1,0,0,0.5)

When working with statusbars you can do:
Lua Code:
  1. local bar = CreateFrame("StatusBar",nil,UIParent)
  2. local tex:CreateTexture()
  3. tex:SetTexture(1,1,1)
  4. bar:SetStatusBarTexture(tex)
  5. bar:SetStatusBarColor(1,0,0,0.5)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 11-22-13 at 01:46 AM.
  Reply With Quote
11-22-13, 07:42 AM   #10
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Seerah View Post
Just FYI, if all you want is a solid color for your texture, you don't need to give it a texture file first and call :SetVertexColor(). You can just use :SetTexture(r,g,b[,alpha])
Hmm i didn't know about that, but i'm pretty sure its the same thing, i can also imagine it's using the same white8x8 texture too.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issues with Textures


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