View Single Post
Unread 12-04-12, 12:11 AM   #5
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,746
You should always define your variables as local. Global variables -- especially ones with single-letter or underscore names -- are extremely likely to collide (overwrite each other) and break addons, other macros, or even the default UI.

After the MoP release, for example, Blizzard was leaking a global variable _ from their UI code, which was colliding with leaked globals of the same name in many addons (it was pretty shocking to realize how many well-known addons are blatantly leaking globals), which was breaking everything.

Code:
/run local m,u,c,_={5,1,1,1,8,1,1,5,3,1,2}for i=0,GetNumGroupMembers()do u=i>0 and 'party'..i or 'player';_,_,c=UnitClass(u)SetRaidTarget(u,m[c])end
Still only 148 characters, giving you plenty of room for additions.

Also, you can omit spaces after closing brackets and parentheses to save more space. The green semicolon highlighted above is interchangable with a space, but I think using a semicolon improves readability and makes it less likely you'll accidentally delete the delimiter while trying to condense things.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote