Help minimizing a macro

What I am trying to do with this macro, is open my bank, and type in the filter on my bags, and click this macro. The macro will then go through my bags and deposit every item that is unfiltered.

I’ve spaced out the macro for readability, and used descriptive names for the variables:

/run local cont=false,item;
	for bag=0,4 do 
		for slot=1,GetContainerNumSlots(bag) do 
			item={GetContainerItemInfo(bag,slot)};
			if item[8]==true then 
    	    	cont=true;
			end;
		end;
	end;
	if cont==true then
		for bag=0,4 do 
			for slot=1,GetContainerNumSlots(bag) do 
				item={GetContainerItemInfo(bag,slot)};
				if item[8]==false then
					UseContainerItem(bag,slot);
				end;
			end;
		end;
	end;

How it works: item[8] is a boolean that says whether the item has been filtered out by the user typing into the backpack search field. So, I first figure out if anything is false (that is, a player has filtered backpack items) and then it attempts to use the unfiltered items (the macro doesn’t know the difference, so it will deposit them to the bank when using the bank interface, or it will sell them when using a vendor interface).

This macro works with just the second loop, but I want the first loop for safety: I want to make sure I’ve filtered at least one item from my inventory, otherwise the macro deposits (or sells) everything.

I know I can change the names of the variables to single letters, and delete the whitespace but that isn’t enough. I have a few more ideas, but so far lowest I can get is 262 characters, and I need to get it less than 255.

First line should be:

/run local cont,item=false

You can save the double handling (twice) of storing the info in a table by using select()

if select(8,GetContainerItemInfo(bag,slot))then 
	cont=true 
end	

Also, you don’t need to use semi colons so as above you can save the character between the end of the function and then.

Small things.

1 Like

/run local n,t,c,i=GetContainerNumSlots,GetContainerItemInfo for b=0,4 do for s=1,n(b) do i={t(b,s)}if i[8] then c end end end if c then for b=0,4 do for s=1,n(b) do i={t(b,s)}if not i[8] then UseContainerItem(b,s)end end end end

229 characters. I didn’t change the structure at all, but I did get aggressive with aliases and I took advantage of the default implied “false” of cont (c in my version).

1 Like