2 and 1.5 are not valid values. Values must be in the range 01 (inclusive). I think WoW does error-correct and treat the 2 as a 1, but it's a simple mistake you can fix.
local hasSecondaryHandEnchant = GetWeaponEnchantInfo()
Programming doesn't work like that. Functions return specific values in a fixed order. Functions also have no awareness of what variables their returned values are being assigned to. You cannot magically get different values or in a different order by assigning them to variables with different names.
You also don't need to two functions to show/hide multiple frames.
Checking for enchants in OnLoad won't work because that information isn't available to the game client yet at that point. Register for PLAYER_ENTERING_WORLD and check there.
Your whole Lua file should look like this:
function MainWeapNote_OnLoad(self)
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UNIT_INVENTORY_CHANGED")
end
function MainWeapNote_OnEvent(self, event, unit)
if event == "UNIT_INVENTORY_CHANGED" and arg1 ~= "player" then return end
local hasMainHandEnchant, _, _, hasSecondaryHandEnchant = GetWeaponEnchantInfo()
local mainHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot"))
local secondaryHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("SecondaryHandSlot"))
local hasFishingPole = mainHandLink and select(7, GetItemInfo(mainHandLink)) == "Fishing Poles"
if ( mainHandLink and not hasFishingPole and not hasMainHandEnchant ) then
MainWeapNote:Show()
else
MainWeapNote:Hide()
end
if ( secondaryHandLink and not hasSecondaryHandEnchant ) then
SecondaryWeapNote:Show()
else
SecondaryWeapNote:Hide()
end
end
And then you should remove the OnLoad and OnEvent handlers for the SecondaryWeapNote frame in your XML file.
Finally, if you're getting errors, post the errors. Just saying "it doesn't work and there are some errors" is pointless.
Also, i have it do that stuff on load, so it will check, one it loads. Because before, it would always pop up when you first logged into the game, even if you had your poison's applied, that way fixed it.
Well, i just hit a road block. I was editing 1 more thing in my .xml's that i wanted to test (Everything has been working perfectly) But that edit didn't work, and it was only a cosmetic edit, so i put the .xml's back to the way they were. Now, neither of the notification's are firing. I'm also not receiving any error's upon load or event firing.
Also, i have it do that stuff on load, so it will check, one it loads. Because before, it would always pop up when you first logged into the game, even if you had your poison's applied, that way fixed it.
That's why I suggested listening for PLAYER_ENTERING_WORLD. Information about your temporary enchants is not available in OnLoad during initial login. It is available in OnLoad if you're just reloading the UI without logging out, but most users will consider an addon that doesn't work without a UI reload to be broken.
In short, here's a list of events that fire on login, in sequence, along with whether or not information about your temporary enchants is available when that event fires:
OnLoad - NO
ADDON_LOADED - NO
SPELLS_CHANGED - YES
PLAYER_LOGIN - YES
PLAYER_ENTERING_WORLD - YES
PLAYER_ALIVE - YES
UNIT_INVENTORY_CHANGED - YES
Here's the same list for a UI reload:
OnLoad - YES
ADDON_LOADED - YES
PLAYER_LOGIN - YES
PLAYER_ENTERING_WORLD - YES
Note that information is always available after a reload, and that some events that fire after logging in do not fire after a reload.
As you can see, PLAYER_ENTERING_WORLD always fires, and the information you want is always available when it does fire. You could use PLAYER_LOGIN instead, but P_E_W will also update your frame when you pass through a loading screen (eg. hearthing, entering/leaving an instance).
2 and 1.5 are not valid values. Values must be in the range 01 (inclusive). I think WoW does error-correct and treat the 2 as a 1, but it's a simple mistake you can fix.
Programming doesn't work like that. Functions return specific values in a fixed order. Functions also have no awareness of what variables their returned values are being assigned to. You cannot magically get different values or in a different order by assigning them to variables with different names.
You also don't need to two functions to show/hide multiple frames.
Checking for enchants in OnLoad won't work because that information isn't available to the game client yet at that point. Register for PLAYER_ENTERING_WORLD and check there.
Your whole Lua file should look like this:
And then you should remove the OnLoad and OnEvent handlers for the SecondaryWeapNote frame in your XML file.
Finally, if you're getting errors, post the errors. Just saying "it doesn't work and there are some errors" is pointless.
Need's to be SecondaryHandSlot
Here are my files:
MainHand.lua
MainHand.xml
RogueNote.toc
SecondHand.lua
SecondHand.xml
That's why I suggested listening for PLAYER_ENTERING_WORLD. Information about your temporary enchants is not available in OnLoad during initial login. It is available in OnLoad if you're just reloading the UI without logging out, but most users will consider an addon that doesn't work without a UI reload to be broken.
For a more detailed explanation of the loading process, see:
http://www.wowpedia.org/Events_that_fire_during_the_loading_process#Saved_variables_loading
In short, here's a list of events that fire on login, in sequence, along with whether or not information about your temporary enchants is available when that event fires:
Here's the same list for a UI reload:
Note that information is always available after a reload, and that some events that fire after logging in do not fire after a reload.
As you can see, PLAYER_ENTERING_WORLD always fires, and the information you want is always available when it does fire. You could use PLAYER_LOGIN instead, but P_E_W will also update your frame when you pass through a loading screen (eg. hearthing, entering/leaving an instance).
I hate XML, so the frames are created in pure Lua. If you want to do it in XML, I'll leave it up to you to figure out how to convert it.