os.clock() vs/ os.time()
Posted: Fri Jul 24, 2015 11:36 am
I was messing around with a custom fight script and started creating my own timer for spell cooldowns and saw that it would still sometimes try to use a skill before the cooldown ends. Then I was looking into os.time() which is what we almost exclusively use for timed events and I noticed a problem...
os.time uses the current system time down to whole seconds. So suppose the actual time is about 3/4 of a second past the whole second. within the next 250 milliseconds, a timer based on os.time() will see that next whole second and think the 1 full second has passed when in actuality, only 250 milliseconds have passed.
I think os.clock() would be a better/more accurate way of doing a timer. Doing my own lua tests with loops to print elapsed time during 3 seconds, and printing difference in both os.time() and os.clock() the script will end prematurely if the repeat ... until... is based on os.time(). Comparatively, if I base the loop on os.clock(), it will run the full time that it's supposed to.
I'm going to further test this tonight by replacing all my os.time() entries in my script with os.clock() and see if my skills fire off more accurately. What are your thoughts on this? Has anyone else looked into this or is there a reason why we typically use os.time() instead of os.clock()?
os.time uses the current system time down to whole seconds. So suppose the actual time is about 3/4 of a second past the whole second. within the next 250 milliseconds, a timer based on os.time() will see that next whole second and think the 1 full second has passed when in actuality, only 250 milliseconds have passed.
I think os.clock() would be a better/more accurate way of doing a timer. Doing my own lua tests with loops to print elapsed time during 3 seconds, and printing difference in both os.time() and os.clock() the script will end prematurely if the repeat ... until... is based on os.time(). Comparatively, if I base the loop on os.clock(), it will run the full time that it's supposed to.
I'm going to further test this tonight by replacing all my os.time() entries in my script with os.clock() and see if my skills fire off more accurately. What are your thoughts on this? Has anyone else looked into this or is there a reason why we typically use os.time() instead of os.clock()?