Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I time a script?

Asked by 10 years ago

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?

0
Ehem, what? Goulstem 8144 — 10y

3 answers

Log in to vote
0
Answered by
ipiano 120
10 years ago

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
Ad
Log in to vote
-2
Answered by 10 years ago

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

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? Orlando777 315 — 10y
Log in to vote
-3
Answered by 10 years ago

you mean like this?

while true do
--etc...
wait(10)
end
0
He said for loop. Goulstem 8144 — 10y
0
while true do is a Loop :P jillmiles1 3 — 10y

Answer this question