Controlled Posted October 18, 2014 Share Posted October 18, 2014 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
Anubhav Posted October 19, 2014 Share Posted October 19, 2014 [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 Link to comment
Controlled Posted October 19, 2014 Author Share Posted October 19, 2014 [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
DiSaMe Posted October 19, 2014 Share Posted October 19, 2014 Coroutines are threads that can suspend their execution until they are resumed: http://www.lua.org/manual/5.1/manual.html#2.11 Link to comment
Controlled Posted October 19, 2014 Author Share Posted October 19, 2014 Coroutines are threads that can suspend their execution until they are resumed: http://www.lua.org/manual/5.1/manual.html#2.11 Having trouble understanding it... Can you give me a example? Link to comment
TAPL Posted October 20, 2014 Share Posted October 20, 2014 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
Controlled Posted October 21, 2014 Author Share Posted October 21, 2014 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now