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"; 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? |
Code:
m={5,1,1,1,8,1,1,5,3,1,2} |
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 |
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. |
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 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. |
Quote:
|
All times are GMT -6. The time now is 06:51 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI