Thread Tools Display Modes
Prev Previous Post   Next Post Next
08-24-14, 03:47 AM   #1
Wimpface
A Molten Giant
 
Wimpface's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 648
Struggling with changing variable value

I'm trying to make my oUF layout load different castbar settings depending on class and spec, and was planning on using a boolean for this but the variable I'm checking never seems to update it's value.

I get no errors, but I've added a debug print to see what isCaster returns and it always returns nil. I've tried this from multiple places in the code (inside the cbCheck function, inside the cbCheckFrame SetScript and inside the Shared function where I create the castbars) and the return is always nil.

This is where I try to change the value.
https://gist.github.com/ShredL/f00b576ae70456a971a8

Lua Code:
  1. -- Doesn't seem to change the value of my isCaster variable
  2. local spec = GetSpecialization()
  3. local _, playerClass = UnitClass("PLAYER")
  4. local isCaster
  5. local function cbCheck()
  6.     if playerClass == 'DRUID' or 'MONK' or 'PALADIN' or 'SHAMAN' then
  7.         if playerClass == 'DRUID' then
  8.             if spec == 1 or 4 then
  9.                 isCaster = true
  10.             else
  11.                 isCaster = false
  12.             end
  13.         elseif playerClass == 'MONK' then
  14.             if spec == 2 then
  15.                 isCaster = true
  16.             else
  17.                 isCaster = false
  18.             end
  19.         elseif playerClass == 'PALADIN' then
  20.             if spec == 1 then
  21.                 isCaster = true
  22.             else
  23.                 isCaster = false
  24.             end
  25.         elseif playerClass == 'SHAMAN' then
  26.             if spec == 2 then
  27.                 isCaster = false
  28.             else
  29.                 isCaster = true
  30.             end
  31.         end
  32.     elseif playerClass == 'DEATHKNIGHT' or 'HUNTER' or 'ROGUE' or 'WARRIOR' then
  33.         isCaster = false
  34.     else
  35.         isCaster = true
  36.     end
  37. end
  38. local cbCheckFrame = CreateFrame("Frame")
  39. cbCheckFrame:RegisterEvent('PLAYER_SPECIALIZATION_CHANGED')
  40. cbCheckFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
  41. cbCheckFrame:RegisterEvent('PLAYER_LOGIN')
  42. cbCheckFrame:SetScript("OnEvent", function()
  43.     cbCheck()
  44. end)

This is what is in my Shared function
https://gist.github.com/ShredL/8ee3b4978b3de4498c4c

Lua Code:
  1. -- Castbar
  2.     if(unit=='player' or unit=='target') then
  3.         local Castbar = CreateFrame('StatusBar', nil, self)
  4.         local Spark = Castbar:CreateTexture(nil, 'OVERLAY')
  5.  
  6.         if(unit=='player') then
  7.             if isCaster == false then
  8.                 Castbar:SetAllPoints(Health)
  9.                 Castbar:SetStatusBarTexture(statusBar)
  10.                 Castbar:SetStatusBarColor(0, 0, 0, 0)
  11.                 Castbar:SetFrameStrata('HIGH')
  12.  
  13.                 Spark:SetSize(2, 7)
  14.                 Spark:SetTexture(1, 1, 1)
  15.             elseif isCaster == true then
  16.                 Castbar:SetAllPoints(Health)
  17.                 Castbar:SetStatusBarTexture(statusBar)
  18.                 Castbar:SetStatusBarColor(0, 0, 0, 0)
  19.                 Castbar:SetFrameStrata('HIGH')
  20.  
  21.                 Spark:SetSize(2, 7)
  22.                 Spark:SetTexture(1, 1, 1)
  23.             end
  24.         else
  25.             Castbar:SetAllPoints(Health)
  26.             Castbar:SetStatusBarTexture(statusBar)
  27.             Castbar:SetStatusBarColor(0, 0, 0, 0)
  28.             Castbar:SetFrameStrata('HIGH')
  29.  
  30.             Spark:SetSize(2, 20)
  31.             Spark:SetTexture(1, 1, 1)
  32.         end
  33.  
  34.         self.Castbar = Castbar
  35.         Castbar.Spark = Spark
  36.  
  37.     end

And here is the entire code if needed
https://gist.github.com/ShredL/59b138b727ca3a818299

It is probably something super simple that I'm overlooking, but I cannot seem to figure out how to change the value of isCaster. Any help is appreciated as always.
__________________
All I see is strobe lights blinding me in my hindsight.

Last edited by Wimpface : 08-24-14 at 04:15 AM.
  Reply With Quote
 

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Struggling with changing variable value

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