View Single Post
05-10-12, 12:56 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,333
After following Haleth's instruction, you need to have your event handler function accept the arguments passed to it. This is the only way to get these values now, it was made available for use in BC and the globals were discontinued in LK. The function signature is as follows, function(self,event,...) where ... is the list of args from the event. You can use vararg here if you want or just supply local variable names to receive the values. Since your function only runs from one event, I'd suggest the later.

On another note, if you don't need to expose your function to the global environment, it's best to make it local. An example of both of these suggestions is to change the function declaration to the following.
Code:
local function najinsniff_OnEvent(self,event,arg1,_,_,_,_,_,_,_,arg9)
Note _ is a valid variable name, most people use it to skip values in a list by tossing it in to discard values they don't want.



There's also an error on the following line:
Code:
SendChatMessage("<Najin> I currently have " .. TRP2_GetCountOfAll("ITE050715543766345") .. " currency." [, "CHANNEL" [, nil [, index]]]);
The brackets as used here is not part of the Lua syntax. This is referred to as BNF notation to show which arguments are optional. In this case, every argument inside each group of brackets [ ] is optional The nesting of each set means one optional argument is dependent on another being supplied. Inserting this line into code will cause the Lua parser to throw an error.



With all of these concerns addressed, this is what I would suggest your code would look like.
Lua Code:
  1. local najinsniff = CreateFrame("Frame");
  2.  
  3. local function OnEvent(self,event,msg,_,_,_,_,_,_,num,name)
  4.     if event=="CHAT_MSG_CHANNEL" and msg=="checkcurrency" and name=="najincom" then
  5.         SendChatMessage("<Najin> I currently have " .. TRP2_GetCountOfAll("ITE050715543766345") .. " currency.","CHANNEL",nil,num);
  6.     end
  7. end
  8.  
  9. najinsniff:RegisterEvent("CHAT_MSG_CHANNEL");
  10. najinsniff:SetScript("OnEvent",OnEvent);
This also has been optimized in which the handler uses the channel number provided by the event to send its response. See http://www.wowpedia.org/Events/Commu...AT_MSG_CHANNEL for the list of arguments passed to the 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