Overkillz Posted September 26, 2017 Share Posted September 26, 2017 Hello dear community. I have a simple question about loops. I have a table with several messages(it is an example), might around 1000. Well, here is my question, could I output them in X time. I don't know, something like all messages could be drop in 20 seconds 20000 ms / 1000 messages ? I know the simple method which is local myTable = { --[[ HERE ARE MY 1000 messages ]] } for i,message in ipairs myTable do outputChatBox(message) end I hope u can understand me. Thanks for reading. Regards. Link to comment
Moderators IIYAMA Posted September 26, 2017 Moderators Share Posted September 26, 2017 (edited) local operationStartTime = getTickCount() --------------- -- operation -- --------------- outputChatBox("It took " .. (getTickCount() - operationStartTime) .. " ms to execute this operation.") Edited September 26, 2017 by IIYAMA Link to comment
Overkillz Posted September 26, 2017 Author Share Posted September 26, 2017 Well, I tried to do it but I didn't get u at all. This is what I have just tried local myTableA = {"Message1","Message2","Message3","Message4","Message5","Message6","Message7","Message8"} local tick = getTickCount() local duration = 5000 function dropMessages() for i,message in ipairs(myTableA) do if getTickCount()-tick>=duration/(i) then outputChatBox(message) end end end addEventHandler( "onClientResourceStart", getRootElement(), dropMessages) Link to comment
Moderators IIYAMA Posted September 27, 2017 Moderators Share Posted September 27, 2017 (edited) I wasn't 100% sure what you were asking for so, I thought I gave it a try. The example does it showing how long lua is busy processing the code in between. But maybe you want to show all messages within X amount of time. local myTableA = {"Message1","Message2","Message3","Message4","Message5","Message6","Message7","Message8"} local messageIndex = 1 local totalDuration = 5000 local durationTimer = math.max(math.ceil(totalDuration / #myTableA), 50) -- can't be lower than 50 ms else the timer doesn't work. addEventHandler("onClientResourceStart", resourceRoot, function () setTimer(function () outputChatBox(myTableA[messageIndex]) messageIndex = messageIndex + 1 end, durationTimer, #myTableA) end) Is this what you are looking for instead? (untested) P.s. loops can be delayed by pause the code, but that is dangerous because you have to manually resume them. (experts only recommended) If you want to know that, I am to happy to send you a link. Edited September 27, 2017 by IIYAMA 1 Link to comment
Moderators IIYAMA Posted September 28, 2017 Moderators Share Posted September 28, 2017 @Overkillz Reminder. 1 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