Thread Tools Display Modes
10-22-09, 11:24 AM   #1
jacob18d
A Deviate Faerie Dragon
Join Date: Apr 2009
Posts: 11
Displaying a simple gold counter

Hey everyone, I'm playing with adding a gold counter to an addon, and while at first glance it appeared to work correctly, today I've noticed it doesn't update, and sometimes it's wrong. This is the code I've got for it, and I'm wondering if anyone can see the errors in my way.

Code:
local GetMoneyResult = GetMoney()/10000;
local Gnumber = tonumber(string.sub(GetMoneyResult ,1,-6)) if Gnumber == nil or Gnumber == 0 then Gnumber = "" else Gnumber = (Gnumber .."|cffe7cb42g|cffffffff ") end
local Snumber = tonumber(string.sub(GetMoneyResult ,-4,-3)) if Snumber == nil or Snumber == 0 then Snumber = "" else Snumber = (Snumber .."|cffaeacaes|cffffffff ") end
local Cnumber = tonumber(string.sub(GetMoneyResult ,-2,-1)) if Cnumber == nil or Cnumber == 0 then Cnumber = "" else Cnumber = (Cnumber .."|cffc29373c|cffffffff") end
local MoneyStats = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge");
MoneyStats:SetPoint("RIGHT", frame, "CENTER", 75*cos(math.pi/1.52), 75*sin(math.pi/1.52));
MoneyStats:SetJustifyH("RIGHT");
MoneyStats:SetShadowOffset(1, -1);
MoneyStats:SetText(Gnumber..Snumber..Cnumber)
I think I'm probably calling the GetMoney() from the wrong place, but I'm not sure how to correct it.
  Reply With Quote
10-22-09, 11:55 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Is that your whole code? Where are you registering for the PLAYER_MONEY event and updating the text?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-22-09, 01:26 PM   #3
jacob18d
A Deviate Faerie Dragon
Join Date: Apr 2009
Posts: 11
Sorry, that wasn't everything I'd put in, I see a lot of problems with what I did, here's what I'm currently at, which mind you doesn't do anything.

Mind you I've been learning to Code LUA for all of about a day, so I'm sure there are a lot of problems with it.

Code:
-- MoneyDisplay OnLoad 

function MoneyDisplay_OnLoad()

   self:RegisterEvent("PLAYER_ENTERING_WORLD");
   self:RegisterEvent("PLAYER_MONEY");

end

-- End MoneyDisplay OnLoad
--
-- MoneyDisplay OnEvent

function MoneyDisplay_OnEvent(self, event, ...)

   if ( event == "PLAYER_ENTERING_WORLD" ) then
      MoneyDisplay = GetMoney();   
      return;

   end 
end

-- End MoneyDisplay OnEvent
--

if ( event == "PLAYER_MONEY" ) then

   local MoneyDisplay  = GetMoney();

end
Code:
local MoneyStats = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge");
MoneyStats:SetPoint("RIGHT", frame, "CENTER", 75*cos(math.pi/1.52), 75*sin(math.pi/1.52));
MoneyStats:SetJustifyH("RIGHT");
MoneyStats:SetShadowOffset(1, -1);
MoneyStats:SetText()
I'm still working on it, and have not quite figured out what I need to do to make it work.
  Reply With Quote
10-22-09, 01:56 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I'm assuming you have an XML file, too? Where do you create your frame named "frame"?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-22-09, 02:06 PM   #5
jacob18d
A Deviate Faerie Dragon
Join Date: Apr 2009
Posts: 11
No XML File. The frame is created in the lua.

Code:
local frame = CreateFrame("Frame",nil,UIParent)
Like I said, I'm trying to add this into an existing addon. Currently it shows Memory Usage, Ping, and FPS on the frame. I've placed text successfully in the correct area of the frame, and I've had it display the amount of gold I have on hand when the game reloads, but I have not been able to figure out how to update the amount of gold when it changes, and have that text update.

I'm thinking I underestimated the difficulty of what seemed like it would be a straight forward process.
  Reply With Quote
10-22-09, 02:52 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Change
Code:
function MoneyDisplay_OnEvent(self, event, ...)

   if ( event == "PLAYER_ENTERING_WORLD" ) then
      MoneyDisplay = GetMoney();   
      return;

   end 
end

-- End MoneyDisplay OnEvent
--

if ( event == "PLAYER_MONEY" ) then

   local MoneyDisplay  = GetMoney();

end
to this:
Code:
function MoneyDisplay_OnEvent(self, event, ...)

   if ( event == "PLAYER_ENTERING_WORLD" ) then
      MoneyDisplay = GetMoney();   
      return;

   elseif ( event == "PLAYER_MONEY" ) then

      local MoneyDisplay  = GetMoney();

   end
end

-- End MoneyDisplay OnEvent
--

/edit: alternately, you can look at my sStats addon (currently in beta) which is a framework to create what you are doing.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-22-09, 03:36 PM   #7
jacob18d
A Deviate Faerie Dragon
Join Date: Apr 2009
Posts: 11
Thank you for your time, but apparently I'm missing something in the whole process. I can't seem to get any data from it, and MoneyDisplay is constantly a nil value. I'm probably just going to scrap the idea for now.
  Reply With Quote
10-22-09, 03:47 PM   #8
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
You're localizing your MoneyDisplay variable inside the if/else statment, that will result in nil:

Wrong:
Code:
if true then
  local MoneyDisplay = GetMoney()
end
print(MoneyDisplay) -- MoneyDisplay = nil
Right:
Code:
local MoneyDisplay
if true then
  MoneyDisplay = GetMoney()
end
print(MoneyDisplay) -- MoneyDisplay = GetMoney()
  Reply With Quote
10-26-09, 10:00 AM   #9
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
You could also try to do this with my addon ncDatatext.
  Reply With Quote
11-18-09, 02:42 AM   #10
Drshow
A Cyclonian
 
Drshow's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 49
hope this helps

Originally Posted by jacob18d View Post
Hey everyone, I'm playing with adding a gold counter to an addon, and while at first glance it appeared to work correctly, today I've noticed it doesn't update, and sometimes it's wrong. This is the code I've got for it, and I'm wondering if anyone can see the errors in my way.
In guild tax i got current gold held to display with coin format with
set text with coin icons
Code:
 local convertedYM -- call for local before OnEvent
 
 function YourMoney() -- call after OnEvent
 Your_Money = GetMoney();
 convertedYM = GetCoinTextureString(Your_Money, " "); --Text string with icons
 if(convertedYM == "") then
  convertedYM = 0;
 end
        YourMoneyText:SetText("Your Money: "..convertedYM..""); -- with icons
 end
set text with out coin icons
Code:
 local convertedYM -- call for local before OnEvent
 
 function YourMoney() -- call after OnEvent
 Your_Money = GetMoney();
 convertedYM = GetCoinText(Your_Money, " "); --Text string without icons
 if(convertedYM == "") then
  convertedYM = 0;
 end
        YourMoneyText:SetText("Your Money: "..convertedYM..""); -- without icons
 end
__________________

Last edited by Drshow : 11-18-09 at 02:47 AM.
  Reply With Quote
11-18-09, 02:49 AM   #11
Drshow
A Cyclonian
 
Drshow's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 49
when you say gold counter

when you say gold counter, are you trying to display current gold with refreshes, or are you counting gold from a source only.
__________________
  Reply With Quote
11-18-09, 10:00 AM   #12
zero-kill
A Firelord
 
zero-kill's Avatar
Join Date: Aug 2009
Posts: 497
I tried to test this, then realized that I don't have any gold on the character :P Fail on my part LOL
  Reply With Quote
11-18-09, 08:23 PM   #13
Drshow
A Cyclonian
 
Drshow's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 49
Originally Posted by zero-kill View Post
I tried to test this, then realized that I don't have any gold on the character :P Fail on my part LOL
lmfao, did it default to 0 or no. I had same issue on PTR n it loaded only double dashes -- untill i called the function.
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Displaying a simple gold counter


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