Jump to content

Slowing down a loop


Controlled

Recommended Posts

Is it possible to slow down how fast a loop runs? Normalling I know it just goes one after the other, is it possible to set some kind of delay there? Right now it causes the whole server to have some lag issues while it runs, I want to slow it down so it lasts longer but doesn't halt the server.

Link to comment
[lua]

someRandomTable = {}

someRandomTabl = {}

for i, v in ipairs(someRandomTable) do

setTimer(runLoop, 5000, 1, someRandomTable)

break

end

function runLoop(t)

for i, v in ipairs(someRandomTable) do

end

end

That would be the exact same outcome, just 5 seconds later. It wouldn't separate them by a time because your first loop is setting a timer really quick anyways....

Link to comment

I was bored so I come out with this code:

aTable = {"Test", abc = "hello", "bla", "421312", www = "a1c234", "W2", "$!@#%!", ["AV"] = true} -- Your table 
aTableMaxEx = 5 -- Max continuous executing. 
  
function doLoop() 
    if not aTableKey then 
        aTableKey, aTableValue = next(aTable, nil) 
    end 
    while aTableKey do 
        if (aTableCount or 0) >= aTableMaxEx then 
            aTableCount = 0 
            setTimer(doLoop, 5000, 1) 
            break 
        end 
        --Your code 
        outputChatBox(tostring(aTableKey)..", "..tostring(aTableValue)) -- Example 
        -- 
        aTableKey, aTableValue = next(aTable, aTableKey) 
        aTableCount = (aTableCount or 0) + 1 
    end 
end 
doLoop() -- Start the loop 

It works with both the numerical keys and the string keys.

Link to comment
I was bored so I come out with this code:
aTable = {"Test", abc = "hello", "bla", "421312", www = "a1c234", "W2", "$!@#%!", ["AV"] = true} -- Your table 
aTableMaxEx = 5 -- Max continuous executing. 
  
function doLoop() 
    if not aTableKey then 
        aTableKey, aTableValue = next(aTable, nil) 
    end 
    while aTableKey do 
        if (aTableCount or 0) >= aTableMaxEx then 
            aTableCount = 0 
            setTimer(doLoop, 5000, 1) 
            break 
        end 
        --Your code 
        outputChatBox(tostring(aTableKey)..", "..tostring(aTableValue)) -- Example 
        -- 
        aTableKey, aTableValue = next(aTable, aTableKey) 
        aTableCount = (aTableCount or 0) + 1 
    end 
end 
doLoop() -- Start the loop 

It works with both the numerical keys and the string keys.

Cool thanks!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...