Jump to content
The simFlight Network Forums
Sign in to follow this  
Matthew Twomey

[Lua] Time in ms

Recommended Posts

Looking through the FSUIPC Lua ref doc. I'd like to be able to get the current time in ms in a script I'm planning out. I believe Lua doesn't have a standard (os-independent) way to do this. Since you have event.timer in your exposed libs (as well as several other ms based functions), I'm guessing you've implemented this in c++ and you're calling something there in your Lua libs. I'm wondering if you'd consider exposing a plain old "get time in ms since the epoch" sort of function in one of your libs? 

Share this post


Link to post
Share on other sites
4 hours ago, Matthew Twomey said:

I'd like to be able to get the current time in ms in a script I'm planning out. I believe Lua doesn't have a standard (os-independent) way to do this.

Which "time" do you want? The windows systems time, the one set on your PC. Or the time in the Sim?

There's an "absolute time" (!!) which is probably the former, as a double in offset 0230.  Local FS time and the related Zulu is given in other offsets nearby.

The time in the Operating System, no matter which, is provided by the Lua os library function os.time.  Most (all in most cases) of the functions in the standard Lua libraries are included in the FSUIPC interpreter, as documented in the Lua PDF provided. For Lua standard library functions please refer to Lua.org (or buy the book! 😉 )

There is a also the elapsed time since FSUIPC was started (ipc.elapsedtime) but I don't think that's what you wanted. 

Pete

 

Share this post


Link to post
Share on other sites
1 hour ago, Pete Dowson said:

The time in the Operating System, no matter which, is provided by the Lua os library function os.time.  Most (all in most cases) of the functions in the standard Lua libraries are included in the FSUIPC interpreter, as documented in the Lua PDF provided. For Lua standard library functions please refer to Lua.org (or buy the book! 😉 )

Yes, this was the point of my post - if you take a look at lua.org, you'll see that os.time() typically returns time in seconds. This indeed appears to be the case in the interpreter you are using in FSUIPC. What I'm looking for is milliseconds.

Thank you for the offset pointer, I didn't think to search the offsets doc for it as an alternative. That gives back milliseconds and that will work for me!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.