Hey, I’m new to Lua so I might be doing this wrong, but I believe that if I call os.time() I should get the current time in seconds. However, I’m getting a constant value (1.33399e+09). I tried passing the current time to it like this: os.time(os.date(‘*t’)) but it returns the same value.
I thought perhaps it was just not printing, but even if I do something like “os.time() % 10”, or os.difftime(…) every frame, I still get a constant.
Is this a bug? And if not, how can I retrieve the time in seconds?
We had a thread about this, but I wasn’t able to find it by searching.
Keep in mind - Codea numbers are only 32 bits (by comparison with desktop Lua at 64 bits). That means that there is no single number that gives you both epoch seconds and the fraction. It’s possible to derive them - I think it was figured out in the thread - but again, can’t find it (I still am getting memory errors when I search), and I’m not going to try to derive it again right this moment.
Yessir, that was the exact thread I was looking for - but I had thought someone had figured out a workaround (which would presumably involve parsing date and so on). Too bad. If nothing else, being able to grab epoch time in seconds is handy.
would this be a good place to re-suggest a high resolution (millisec or higher) timer that would reset at each call to draw? With this we would have a way to measure the time some things take in a resolution higher that 1/60th of a second, and would not (be so likely to) hit the 24-bit integral value limit of 32-bit floats.
You’re talking about precision. By resolution i mean the minimum difference between 2 consecutive values you can read. In the case of ElapsedTime and DeltaTime, this is 1/60th second at best, which is about 17 msec. Also, by the very nature of the system, this resolution can not be guaranteed.