View Single Post
09-08-11, 04:22 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
In all honesty, the existing API already does something like this.
lua Code:
  1. local frame=CreateFrame("Frame");
  2. frame:RegisterEvent("MERCHANT_SHOW");
  3. frame:RegisterEvent("MERCHANT_CLOSED");
  4.  
  5. local money=0;
  6. frame:SetScript("OnEvent",function(self,event,...)
  7.     if event=="MERCHANT_SHOW" then
  8.         money=GetMoney();
  9.     elseif event=="MERCHANT_CLOSED" then
  10.         local diff=GetMoney()-money;
  11.         if diff~=0 then
  12.             print(diff>0 and "You made" or "You spent",GetCoinTextureString(math.abs(diff)));
  13.         end
  14.     end
  15. end);

You create a UI object known as a Frame. Through this, you can register for certain event callbacks to be received through the Frame's OnEvent handler.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote