View Single Post
02-18-12, 09:44 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I see several problems with your code, SDPhantom...

#1 - You typed semicolons instead of commas inside a table definition:
Code:
local FactionRaces={
	Dwarf		="Alliance";
	Draenei		="Alliance";
#2 - You typed semicolons anywhere. Semicolons are not necessary or useful in Lua. All they do is to make your code harder to read by adding visual clutter.

#3 - The player's GUID is not available when the main chunk executes at login, so this will not work:
Code:
local PlayerGUID=UnitGUID("player");
It will work on a UI reload, but not on a fresh login.

#4 - I don't really know what you were trying to do here:
Code:
BRFrame:SetScript("OnEvent",function(self,event,...)
	local guid,msg,sender=select(12,...),...;
Not only will this not work the way you intended (select returns the specified value and all subsequent values, so this call will set guid=arg12, msg=arg13, and sender=arg14) but it's unnecessarily convoluted. Just name the values in the order they appear, "discarding" the unwanted ones with a junk name:
Code:
BRFrame:SetScript("OnEvent", function(self, event, ...)
	local msg, sender, _, _, _, _, _, _, _, _, _, guid = ...
Also, an addon isn't a space-limited macro. Conventional use of spaces makes your code much easier to read.

#5 - This:
Code:
	if guid~=PLAYER_GUID then--	Don't respond to emotes the player sent.
		-- Do stuff here.
	end
... is slower than this:
Code:
	if guid == PLAYER_GUID then return end -- Don't respond to emotes the player sent.

	-- Do stuff here.
If there's only one condition, and you simply want to "do nothing" if it isn't met, just return. Otherwise, the parser has to run through the whole block of code to see if there's an "else" keyword, or anything after the "if ... end" block, for it to execute.

I don't have time to go through it in more detail than that right now, but there may be other issues as well.

TL;DR: Don't write code while you are falling asleep.
  Reply With Quote