Go to Page... |
|
Thread Tools | Display Modes |
|
08-25-14, 02:50 AM | #1 | ||||
Functions like UnitGUID don't return useful values right away on a fresh login, and most likely GetSpecialization doesn't either. You can easily test this by logging out to the character screen and logging back in, with the following code in the main chunk: Code:
print("Current spec is:", GetSpecialization())
OnLoad doesn't fire for frames created in Lua, and doesn't need to, as it's the same as just writing the code directly after the CreateFrame call. If you're not using oUF:Factory already, I'd recommend you switch to it, as it will delay creating your frames until PLAYER_LOGIN, at which time information about things like your spec should be available, even on a fresh login.
__________________
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. |
|||||
08-25-14, 04:06 AM | #2 | |||||
The only difference is at line 192, the cbCheck() function This works on a fresh login: https://gist.github.com/ShredL/d785e8761d9736d252d5 This doesn't (p3lim's check): https://gist.github.com/ShredL/f9657dd9c9538a89e9ef Why does one work and not the other? From what I can see, the only difference is cleaning up the if statements. Printing the first (working) version of isCaster returns the correct value on fresh login and reload while printing the other one returns nil on both login and reload. I appreciate all the help! EDIT: This reply was messy, I was changing things around as I was testing new things etc and it got really messy. Summary is that it is working correctly when it apparently shouldn't have (first gist) and it isn't working correctly like it apparently shouldn't when using p3lim's suggestion (second gist).
__________________
All I see is strobe lights blinding me in my hindsight. Last edited by Wimpface : 08-25-14 at 04:09 AM. |
||||||
08-25-14, 09:02 AM | #3 | ||
You can trim it down more with: Code:
local isCaster local cbCheck = function() if playerClass == 'DRUID' then isCaster = (GetSpecialization() or 0) % 3 == 1 elseif playerClass == 'MONK' or playerClass == 'SHAMAN' then isCaster = GetSpecialization() == 2 elseif playerClass == 'PALADIN' then isCaster = GetSpecialization() == 1 else isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK' end end |
|||
08-26-14, 12:19 AM | #4 | ||
I even made a little video to show that it works on a fresh login on my caster Shaman, my caster Mage and my melee Monk. Excuse shoddy framerate but text should be very readable atleast: http://www.youtube.com/watch?v=w6_gm2KBH5I Is it because of what Phanx said earlier about oUF:Factory delaying the creation of frames until PLAYER_LOGIN? Don't get me wrong, I'm really happy it works, I'm just curious why it does because it apparently shouldn't, and I simply don't have the knowledge to understand the logic behind it.
__________________
All I see is strobe lights blinding me in my hindsight. |
|||
08-26-14, 08:01 AM | #5 | |
Try your code on a druid, monk, or paladin caster; or a melee shaman, and see if it works. The only reason it works now is because when GetSpecialization() returns nil the default fall through value is what you wanted anyway (for the classes you tested). Also, the code I posted should be changed to: Code:
local isCaster local cbCheck = function() if playerClass == 'DRUID' then isCaster = (GetSpecialization() or 0) % 3 == 1 elseif playerClass == 'MONK' then isCaster = GetSpecialization() == 2 elseif playerClass == 'PALADIN' then isCaster = GetSpecialization() == 1 elseif playerClass == 'SHAMAN' then isCaster = GetSpecialization() ~= 2 else isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK' end end |
||
08-26-14, 10:12 AM | #6 | |||
I'm going to try waiting for PLAYER_LOGIN to fire and see if that helps me.
EDIT: Back to where it doesn't work on reload but seems to work on a fresh login now. Code here: https://gist.github.com/ShredL/1ebcc6b803a0aaab86ea isCaster check on line 192, castbar creation at line 277. It prints isCaster correctly now, just doesn't spawn a castbar after reloading and I don't know why.
__________________
All I see is strobe lights blinding me in my hindsight. Last edited by Wimpface : 08-26-14 at 10:19 AM. |
||||
08-26-14, 07:39 PM | #7 |
Try replacing:
Code:
local isCaster local cbCheckFrame = CreateFrame("Frame") cbCheckFrame:RegisterEvent("PLAYER_LOGIN") cbCheckFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED") cbCheckFrame:SetScript("OnEvent", function() if playerClass == 'DRUID' then isCaster = (GetSpecialization() or 0) % 3 == 1 elseif playerClass == 'MONK' then isCaster = GetSpecialization() == 2 elseif playerClass == 'PALADIN' then isCaster = GetSpecialization() == 1 elseif playerClass == 'SHAMAN' then isCaster = GetSpecialization() ~= 2 else isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK' end print(isCaster) end) Code:
local detectTalentChange = CreateFrame('Frame') detectTalentChange:SetScript('OnEvent', function(self) if not self.unitFrame then return end local isCaster if playerClass == 'DRUID' then isCaster = (GetSpecialization() or 0) % 3 == 1 elseif playerClass == 'MONK' then isCaster = GetSpecialization() == 2 elseif playerClass == 'PALADIN' then isCaster = GetSpecialization() == 1 elseif playerClass == 'SHAMAN' then isCaster = GetSpecialization() ~= 2 else isCaster = playerClass == 'MAGE' or playerClass == 'PRIEST' or playerClass == 'WARLOCK' self:UnregisterAllEvents() self:SetScript('OnEvent', nil) end if isCaster ~= self.isCaster then self.isCaster = isCaster local Castbar = self.unitFrame.Castbar Castbar:ClearAllPoints() if isCaster then Castbar:SetPoint('TOP', self.unitFrame, 'BOTTOM', 0, -68) Castbar:SetStatusBarColor(1, 1, 1) Castbar:SetSize(barWidth, 4) Castbar:SetBackdrop(backdrop) Castbar:SetBackdropColor(0, 0, 0) if Castbar.Spark then Castbar.Spark:Hide() end else Castbar:SetAllPoints(self.unitFrame.Health) Castbar:SetStatusBarColor(1, 1, 1, 0.5) Castbar:SetBackdrop(nil) if not Castbar.Spark then local Spark = Castbar:CreateTexture(nil, 'OVERLAY') Spark:SetSize(2, 7) Spark:SetTexture(1, 1, 1) Castbar.Spark = Spark end Castbar.Spark:Show() end end end) detectTalentChange:RegisterEvent('ACTIVE_TALENT_GROUP_CHANGED') detectTalentChange:RegisterEvent('PLAYER_LOGIN') Code:
if(unit=='player' or unit=='target') then local Castbar = CreateFrame('StatusBar', nil, self) Castbar:SetStatusBarTexture(statusBar) Castbar:SetFrameStrata('HIGH') self.Castbar = Castbar if(unit=='player') then detectTalentChange.unitFrame = self else Castbar:SetPoint('BOTTOM', UIParent, 'CENTER', 0, 200) Castbar:SetStatusBarColor(1, 0, 0) Castbar:SetBackdrop(backdrop) Castbar:SetBackdropColor(0, 0, 0) Castbar:SetSize(350, 24) local Time = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall') Time:SetFont(nameFont, nameFontSize, 'OUTLINE') Time:SetTextColor(1, 1, 1) Time:SetPoint('RIGHT', Castbar) Castbar.Time = Time local Text = Castbar:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall') Text:SetFont(nameFont, nameFontSize, 'OUTLINE') Text:SetTextColor(1, 1, 1) Text:SetPoint('LEFT', Castbar, 'LEFT', 4, 0) Castbar.Text = Text local Icon = Castbar:CreateTexture(nil, 'OVERLAY') Icon:SetSize(24, 24) Icon:SetPoint('RIGHT', Castbar, 'LEFT', -6, 0) Castbar.Icon = Icon local Shield = Castbar:CreateTexture(nil, 'OVERLAY') Shield:SetSize(64, 64) Shield:SetPoint('CENTER', Icon, 'CENTER', 12, 0) Shield:SetTexture([[Interface\CastingBar\UI-CastingBar-Arena-Shield]]) Castbar.Shield = Shield end end |
|
WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Struggling with changing variable value |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|