I've written a small, personal addon that deals with gold and mail to be sent to my bank toon. I've run into a little problem and I'm stuck. The addon is a small frame that shows a tooltip with my current gold and the amount of gold I have gained or lost that session along with some other information.
The XML has the following:
Code:
<OnEnter>
tooltip()
</OnEnter>
This is my basic code:
Code:
local startgold = GetMoney()
function tooltip()
local money = GetMoney()
GameTooltip:SetOwner(frame, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", "frame", "BOTTOMLEFT")
GameTooltip:AddLine("Title", .4,.7,.8)
GameTooltip:AddDoubleLine("Current Gold:", GetCoinTextureString(money))
if startgold >= money then
local sessiongold = startgold - money
GameTooltip:AddDoubleLine("Session Gold:", GetCoinTextureString(sessiongold))
else
local sessiongold = money - startgold
GameTooltip:AddDoubleLine("Session Gold:", GetCoinTextureString(sessiongold))
end
GameTooltip:Show()
end
I simplified the code for posting here. My variables and functions are named a little better in the actual code.
The problem is "startgold" is nil when the addon loads. I've tried to put it in the XML in <OnLoad>. I've tried to use events like ADDON_LOADED and PLAYER_ENTERING_WORLD but none seem to work. I've downloaded a couple mods that do this already but being a beginner at programming, I have trouble following their code. Can someone point me in the right direction? Any help would be greatly appreciated.