I am creating my own addon with some UI configurations etc and most of it seem to work fine.
But I am having an issue with the following code where I am trying to hide the stancebar (stealth button) when I login on my rogue:
local f = CreateFrame("frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
if (UnitClass("Player") == "Rogue") then
StanceBarFrame:Hide()
end
end)
After logging in the stance bar is still visible, but running below while ingame hides it successfully:
/run if UnitClass("Player") == "Rogue" then StanceBarFrame:Hide() end
Also using the same code for detecting login works for sending a basic chat message to test etc. I can’t see what I am doing wrong.
Update:
I now tried this
local f = CreateFrame("frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function()
if (_G.UnitClass("Player") == "Rogue") then
print("Class is Rogue")
StanceBarFrame:Hide()
else
print("Class is not Rogue")
end
end)
And it does print “Class is Rogue” in the chatbox when i login to my rogue, so my IF statement does work. It just wont hide the StanceBarFrame through it.
Just running /run StanceBarFrame:Hide() ingame works fine. It’s almost as if Blizzards ui loads it after my code already has run