### Author Topic: function time()  (Read 774 times)

#### lost_mind

• Newbie
• Posts: 8
##### function time()
« on: September 11, 2016 »
can i find an example with time() funct heavily described?
I would like to know how to retrieve the precise time of my system(e.g do a clock)
Or increment a var every second.
if i understand well time() return milsec so if i divide by 1000 it give me second.
But other than that i am a bit confused.

Thanks and see you

#### B+

• Full Member
• Posts: 215
##### Re: function time()
« Reply #1 on: September 11, 2016 »
Timer ?

Code: [Select]
`set window 100, 40, 600, 400t = time()'wait .5 sec or 5 sec comment out 5000delay = 500delay = 5000x = 0while (time() - t < delay) x = x + 1wendwln x/1000000, " Time's up! press any..."wait keydown`
EDIT: I changed above code.

I don't know why time() returns negative numbers, don't know how to relate it to time of day.
« Last Edit: September 11, 2016 by B+ »
B+

#### cvirus

• Jr. Member
• Posts: 72
##### Re: function time()
« Reply #2 on: September 11, 2016 »
You can use an extension names ksink. http://www.naalaa.com/forum/index.php?topic=332.0

#### lost_mind

• Newbie
• Posts: 8
##### Re: function time()
« Reply #3 on: September 11, 2016 »
ok thanks
this stuff seem a bit confusing.
I will try another way maybe.
I would be curious marcus explain what does time() function return, and maybe naalaa itself could format it.

Great thank anyway

#### B+

• Full Member
• Posts: 215
##### Re: function time()
« Reply #4 on: September 11, 2016 »
ok thanks
this stuff seem a bit confusing.
I will try another way maybe.
I would be curious marcus explain what does time() function return, and maybe naalaa itself could format it.

Great thank anyway

Are you aware of strict adherence to floats (versus integers) yet?
B+

#### lost_mind

• Newbie
• Posts: 8
##### Re: function time()
« Reply #5 on: September 12, 2016 »
No not aware of that.
I am not a math man anyway...
But sure thing is Naalaa is very friendly user stuff...
Wait and see if marcusgot some time to light up stuff about time() function.
thanks and see you

and i have tried that:
Code: [Select]
`'test 11092016visible : var = 0set window 0, 0, 320, 240, false, 2set redraw offdoset color 0,0,0clsset color 255, 255, 255set caret 0,0wln "Press space bar to exit ..."set caret 50,50randomize time()wln time()/1000var = var + time()wln varredrawuntil keydown(" ", true)`
and the var = var + time sometimes give negative number it is very strange
« Last Edit: September 12, 2016 by lost_mind »

#### B+

• Full Member
• Posts: 215
##### Re: function time()
« Reply #6 on: September 12, 2016 »
Hi lost_mind,

From your code, I see something you might be after that I missed.

I have converted my example of timer to using floats and show seconds elapsed until time's up.
This should give you a taste of what is needed to do math with floats. Maybe you know already?

The thing I did not fully realize was that the absolute value of time() actually decreases as time progresses!!!
How NOT intuitive is that!?!?

Code: [Select]
`' timer.txt for Naalaa [B+=MGA] 2016-09-12' 2016-09-12 mods' what is with time() that time start - current time > 0 ?' mod revise timer.txt with floats to show fractions of secs passing' note: one trick with using floats is to remember number literals have'       to look like floats too! with decimal and 0 eg'       for .1 use 0.1'       for 5  use 5. or 5.0'          Also it helps to use # after first declared to remember float math'       var# = 0.0'       var# = 10.0 + 5.0 * var#set window 100, 40, 600, 400set redraw offstart# = float(time())wln "float(time()) = start: ", start#'to wait .5 sec comment out 2nd delay# = 5.0'notice error if I use just .5 in nextdelay# = 0.5'notice error if I use just 5 in nextdelay# = 5.0wln "We will signal when ", delay#, " seconds have passed."'notice errors if I use 0 or .0 in next, floats apply to number literalst# = 0.'I liket# = 0.0while t# < delay# '!!!!!!! ' unlike with procedure wait ms, you can do things while "timer" is counting down 'blank out last reading set colori 0 draw rect 0, 40, 600, 400 - 40, true 'show next set caret 10, 40 set colori 0xffffff current# = float(time()) wln "float(time()) = current time(): ", current# 'OH, the current time is decreasing in absolute size !!!!!!!!!!!!!!!!!!!!!!! 'OK, since current < start in absolute terms subtract current from start 'since both are negative multiply by -1 for show and compare to positive delay# 'divide by 1000 to convert into secs, approximately t# = -1.0 * (start# - current#) / 1000.0 wln "Estimate secs passed: ", t# redrawwendwln "Time's up! press any..."redrawwait keydown`
« Last Edit: September 12, 2016 by B+ »
B+

#### lost_mind

• Newbie
• Posts: 8
##### Re: function time()
« Reply #7 on: September 14, 2016 »
Ok
I understand better the stuff now.
But defintly not very intutive with all the respect that is due.
Great thank
see you

#### Marcus

• Hero Member
• Posts: 549
##### Re: function time()
« Reply #8 on: July 14, 2017 »
Oh god, I've missed some threads

The function time() works just like timeGetTime in Windows (C++) and returns the time elapsed since Windows started

In the next update I'll change it to return the time that's passed since the program started instead, makes more sense (atleast for me).

« Last Edit: July 14, 2017 by Marcus »
.\\\opz