Getting system time in gadgets (unsynced)

Getting system time in gadgets (unsynced)

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Getting system time in gadgets (unsynced)

Post by Tribulex »

I need to get the system time in an unsynced gadget. System.time doesnt work so how can i do it?
slogic
AI Developer
Posts: 626
Joined: 17 Mar 2008, 19:03

Re: Getting system time in gadgets (unsynced)

Post by slogic »

Try os.date(), os.time().
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Getting system time in gadgets (unsynced)

Post by zwzsg »

Keep in mind that due to the limited precision of Lua numbers, os.time() is rounded to the nearest dozen seconds.

Use Spring.GetTimer() and Spring.DiffTimers(timer,timer) if you need precision.

Use os.date(..) if you need a formatted string showing current time.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Getting system time in gadgets (unsynced)

Post by Tribulex »

yeah thats what i mean os.time throws errors in gadgets.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Getting system time in gadgets (unsynced)

Post by zwzsg »

In synced gadget, that's normal: The clocks of all the computers aren't synced, so os.time is disabled so you don't cause desyncs by using it. In unsynced gadget, I don't know if I ever tried, but that's still not what I meant.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Getting system time in gadgets (unsynced)

Post by Tribulex »

unsynced gadget. Yes synced makes sense, but why not unsynced. I dont really want to make this a widget.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Getting system time in gadgets (unsynced)

Post by lurker »

Either get somebody to add some of the widget calls to unsynced or possibly make a widget do it.

I think the game ID has a timestamp embedded in it, and there might be other functions that can return a timestamp.
User avatar
Tribulex
A.N.T.S. Developer
Posts: 1894
Joined: 26 Sep 2009, 21:26

Re: Getting system time in gadgets (unsynced)

Post by Tribulex »

ya i forgot about this. Ill have to check what i did in my music gadget
Post Reply

Return to “Lua Scripts”