So, I've been working on more source for personal use.
I've seen many addons that somehow utilize a pause. I searched quite a bit to no avail. In particular, those addons that arrange bags seem to have a timed delay in activity during execution.
My thinking was.. if I can use the user defined wait() function to act as the fire for iteration, I can use and increment a table to define my iteration start pts each time wait() fires. (note that wait(), itself, does not increment the table values, the incrementing takes place in the deepest nested loop, as you can see in my code below.)
So, in essence, this is a triple nested loop that is broken (hard return) on the inner most level each time. (only after incrementing the table values from which the loops obtain their start point and then invoking the wait() function) .
This allows for less code than using if/then in place of the loops.
This can also be re-worked in a number of ways, and is versatile to many concepts.
I'm no pro, so I was hoping for feedback. Whatsup?
(also stickied for those of u who prefer it:
http://www.wowace.com/paste/4089/)
Code:
local t={}
local startLoop
local printNext
local waitTable = {};
local waitFrame = nil;
SLASH_CPCMD1, SLASH_CPCMD2 = 'signpost', '/sp';
function SlashCmdList.CPCMD(msg, editbox)
if msg == "test" then
print ("pressed now")
firePrism_wait(5, print, "printed 5 seconds later")
end
if msg =="test2" then
startLoop()
end
end
SlashCmdList["cpcmd"] = SlashCmdList.CPCMD
function startLoop()
t.gemType = t.gemType or 1
t.bag = t.bag or 0
t.slot = t.slot or 1
for i=t.gemType, 6 do
for j = t.bag+1, 5 do
for k= t.slot, 14 do
printNext("gem= "..t.gemType..", bag = "..t.bag..", slot = "..t.slot)
if k == 14 then
t.bag = t.bag+1
t.slot = 0
end
if j == 5 and t.slot == 0 then
t.gemType = t.gemType+1
t.bag = 0
print("Next gem")
end
t.slot = t.slot+1
return
end
end
end
end
function printNext(myString)
--print(myString)
firePrism_wait(.2, print, myString)
end
function firePrism_wait(delay, func, ...)
if(type(delay)~="number" or type(func)~="function") then
return false;
end
if(waitFrame == nil) then
waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
waitFrame:SetScript("onUpdate",function (self,elapse)
local count = #waitTable;
local i = 1;
while(i<=count) do
local waitRecord = tremove(waitTable,i);
local d = tremove(waitRecord,1);
local f = tremove(waitRecord,1);
local p = tremove(waitRecord,1);
if(d > elapse) then
tinsert(waitTable,i,{d-elapse,f,p});
i = i + 1;
else
count = count - 1;
f(unpack(p));
startLoop()
end
end
end);
end
tinsert(waitTable,{delay,func,{...}});
return true;
end
This can be used in a number of ways, but suits me for splitting and sorting items in bags without overlap in slot population causing errors. My area of interest for this code is gems(in this case, the 6 green cata gems). In use, table t{} contains location and quantity information about each gem, but like I said, this template could be useful to others in other ways.
Thanks for checking it out, I'd love any comments/advice.