Originally Posted by Clamsoda
Edit: I am not sure how to break out of nested loops in Lua, the code may be able to be optimized a bit if someone sheds some light on that aspect.
|
What you'd have to end up doing is set a variable in the inner loop for a conditional in the outer loop to check for and break out if needed. The following example has the dual purpose of getting the position and breaking out of both loops when it's found.
Lua Code:
-- Example of an item link
local _,link=GetItemInfo(6948);
local bag,slot;-- These are nil to start with
for i=0,NUM_BAG_SLOTS do
for j=1,GetContainerNumSlots(i) do
if GetContainerItemLink(i,j)==link then
bag,slot=i,j;-- Set vars
break;-- Breaks out of inner loop
end
end
-- Break out of outer loop if vars have been set by inner loop
if bag and slot then break; end
end