os.clock() vs/ os.time()

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

os.clock() vs/ os.time()

#1 Post by noobbotter » 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()?

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: os.clock() vs/ os.time()

#2 Post by rock5 » Fri Jul 24, 2015 11:55 am

I think you'll find that they are both used, usually os.clock() being used when fraction of a second accuracy is needed.

I used to use os.clock() all the time until Administrator encouraged me to use getTime() and deltaTime(). Now I usually use that.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

noobbotter
Posts: 527
Joined: Fri Aug 31, 2012 1:15 pm

Re: os.clock() vs/ os.time()

#3 Post by noobbotter » Fri Jul 24, 2015 12:04 pm

I saw that. After my post I was looking through the skills.lua file and saw the getTime and deltaTime but wasn't sure what those were. I might look into those some. Thanks. I think once I implement this fix on the script I was making, my WoundAttacks should be much more accurate.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: os.clock() vs/ os.time()

#4 Post by rock5 » Fri Jul 24, 2015 12:53 pm

getTime() returns a table which is not much use on it's own. You use geltaTime to return the difference between the current time and the previous saved getTime. Eg.

Code: Select all

start=getTime()
...
print(deltaTime(getTime(),start))
The returned time is in ms and fractions of a ms so it's wickedly accurate eg. 3613.2839382885ms, but then who needs better accuracy than thousandths of a second os.clock() gives?
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: os.clock() vs/ os.time()

#5 Post by beanybabe » Thu Jul 30, 2015 11:24 am

This post on multi-core cpu speed seems to have some info on what you are looking for but its over my head. It has to do with different timers and buss speed etc.
http://www.solarstrike.net/phpBB3/viewt ... =21&t=6119 follow the link to the ms article.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 7 guests