WoWInterface

WoWInterface (http://www.wowinterface.com/forums/index.php)
-   Macro Help (http://www.wowinterface.com/forums/forumdisplay.php?f=140)
-   -   Mapping/optimize stuff in LUA to make it fit in a macro? (http://www.wowinterface.com/forums/showthread.php?t=45361)

drojden 12-03-12 07:43 PM

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?

Vrul 12-03-12 08:07 PM

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.

drojden 12-03-12 08:08 PM

nvm figured it out by my self.
Just put the mapping into an array :D

/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

drojden 12-03-12 08:16 PM

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 :D )

Anyway, thanks alot for the help.

Phanx 12-04-12 12:11 AM

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.

pelf 12-08-12 02:53 AM

Quote:

Originally Posted by Phanx (Post 270164)
(it was pretty shocking to realize how many well-known addons are blatantly leaking globals)

It wasn't really that shocking, was it?


All times are GMT -6. The time now is 10:51 AM.

vBulletin © 2014, Jelsoft Enterprises Ltd
©2012 ZAM Network LLC