I have a script with a for loop, how do I time that loop so I know when to call a certain event? Or does it all vary with processing power and technical stuff like that?
✓ ANSWER ACCEPTED
How do I time a script?
3 answers
✓ Accepted answer
I believe what you need is this.
while true do
local timeStart = time()
--TODO: Finish the loop(aka, other stuff in the loop)
wait()
--[=[From what I can tell, you must call wait **before** you get the second time; it may help to also call wait before you get the first time because according to the wiki, "wait() must be called for time to update]=]
local timeEnd = time()
print("Total time is "..(timeEnd-timeStart))
end
I think this might be what you are looking for:
for i = 0, 50 --change the fifty for how long you want the loop to run
if i == 5 do
print("i is equal to five!") -- put certain event in here
wait(1)--currently set to one sec, this is so the timer does not get interrupted
else -- if it is not equal to five do this stuff
wait(1) -- again set to one sec
end
end
1 comment
0
I mean literally time the script .-. Here's an example. it took 1.1 seconds for the script to read and do what was written in it. I believe it had something to do with coorutines?
you mean like this?
while true do
--etc...
wait(10)
end
2 comments
0
He said for loop.
0
while true do is a Loop :P
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Ehem, what?