Thread Tools Display Modes
12-03-12, 07:43 PM   #1
drojden
A Defias Bandit
Join Date: Dec 2012
Posts: 3
Mapping/optimize stuff in LUA to make it fit in a macro?

Hello i'm doing a macro that will put specific marks on specific classes in arena.

This is what i have done so far.

/script v="player";for p=0,GetNumGroupMembers() do if(p>0) then v="party"..p;end;q,x,c=UnitClass(v); m=1;if c==11 then m=2; elseif c==5 then m=8; elseif c==1 then m=5; elseif c==8 then m=5; elseif c==9 then m=3; end;SetRaidTarget(v, m);end

Same code but easier to read:
Code:
v="player";
for p=0,GetNumGroupMembers() do 
    if(p>0) then 
        v="party"..p;
     end;
     q,x,c=UnitClass(v); 
     m=1;
     if c==11 then 
          m=2; 
     elseif c==5 then 
          m=8; 
     elseif c==1 then 
          m=5; 
     elseif c==8 then 
          m=5; 
     elseif c==9 then 
          m=3; 
     end;
     SetRaidTarget(v, m);
end
Pretty basic, getting the class id for all party members including my self and mapping marks ID to the class ID. "c" is Class ID and "m" is Mark ID in the code above.

Only problem is that the macro is using 239/255 chars and so far i have only covered 5 of the 11 classes that are available in game. Is there anyway to minimize my code with mapping or in any other way?
  Reply With Quote
12-03-12, 08:07 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Code:
m={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
Table 'm' is the markID listed in classID order.
  Reply With Quote
12-03-12, 08:08 PM   #3
drojden
A Defias Bandit
Join Date: Dec 2012
Posts: 3
nvm figured it out by my self.
Just put the mapping into an array

/script a={1,2,4,1,8,7,5,6,3,4,5}; v="player";for p=0,GetNumGroupMembers() do if(p>0) then v="party"..p;end;q,x,c=UnitClass(v); m=a[c]; SetRaidTarget(v, m);end
  Reply With Quote
12-03-12, 08:16 PM   #4
drojden
A Defias Bandit
Join Date: Dec 2012
Posts: 3
oh u just posted few second before me.

Your code was even more optimized, then i might have some room to make a buffer and make exception for the 3 comps that will miss a guy with mark.

In my array it will be comps with:
hunter and monk
rogue and warrior
druid and shaman

since those classes share the same mark ( 8 mark and 11 classes )

Anyway, thanks alot for the help.
  Reply With Quote
12-04-12, 12:11 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
12-08-12, 02:53 AM   #6
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Originally Posted by Phanx View Post
(it was pretty shocking to realize how many well-known addons are blatantly leaking globals)
It wasn't really that shocking, was it?
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » Macro Help » Mapping/optimize stuff in LUA to make it fit in a macro?

Thread Tools
Display Modes

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