Can someone give me an example of code that shows:
do x,
timer starts,
prints current time [loop],
do y,
timer stops,
prints time taken [event].
I'm new to lua and cannot get my head around this, I'd appreciate if you could help :unsmith:
For learning Lua i suggest you move your question to the Newbie Section :
[url]http://www.facepunch.com/forumdisplay.php?f=337[/url]
What difference would that make, it isn't like different people browse the two sections :buddy:
[QUOTE=LODY;22631949]What difference would that make, it isn't like different people browse the two sections :buddy:[/QUOTE]
Actually, i barely come in requests since i already have projects i am working on, i do come to Newbie Questions to help out.
[editline]03:47PM[/editline]
As for the actual question i am not sure what you mean, timers work like this :
[lua]print("Timer started at time : "..CurTime())
timer.Simple(2,function()
print("Timer finished at time : "..CurTime())
end)[/lua]
Basically, it is like measuring time taken to get from A to B.
The timer counts up until the player gets to B.
ontrigger (whatever the player does to start the timer)
timer (something that counts up in seconds)
ontrigger (whatever the player does to end the timer)
and then a result that prints the completed time.
I couldn't find any docs that show this so that's why I'm stuck :smith:
Something like this probably :
[lua]local TimeStarted = {} // Create our table that we store the start time in.
function Start_Timer(ply) // Called when the console command IStart is ran.
TimeStarted[ply:UniqueID()] = CurTime() // Set the time to the current time.
end
concommand.Add("IStart",Start_Timer) // Link the console command to the function
function Stop_Timer(ply) // Called when the console command IArrived is ran.
print(CurTime()-TimeStarted[ply:UniqueID()]) // print the time that has elapsed.
TimeStarted[ply:UniqueID()] = nil // Removing the time from the table.
end
concommand.Add("IArrived",Stop_Timer) // Link the console command to the function[/lua]
Thank you so much :buddy:
I think I now understand this better, especially with the comments!
[QUOTE=LODY;22632318]Thank you so much :buddy:
I think I know understand this better, especially with the comments![/QUOTE]
No problem, if you have any questions just add me on Steam (Under my avatar).
Sorry, you need to Log In to post a reply to this thread.