System time in ZScript

Moderator: GZDoom Developers

User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

System time in ZScript

Post by NightFright »

I am looking for a way to show current system time instead of level/hub time. If possible in both 12h and 24h formats (e.g. 08:15 PM vs 20:15).

Is this possible in ZScript, and if so, how is it done?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49225
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: System time in ZScript

Post by Graf Zahl »

Currently there is no access to the system time from ZScript.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: System time in ZScript

Post by NightFright »

Is this something you'd be considering for a feature request? I am sure this could prove useful, not only for my own project.
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: System time in ZScript

Post by Rachael »

Only way this will happen is if it's UI-scope only. The game world is deterministic by nature and external influences (such as time) would ruin that.

I'm thinking the best way to implement this is to create and expose a UI element that can be accessed that gives a Unix timestamp only, and possibly a local timezone offset. Then, functions can be made to extend that element to internally determine the correct time from that timestamp.

Unfortunately, however, without access to 64-bit ints, such an implementation would be weak to the 32-bit timestamp overflow issue happening in 2038.

This however, sounds like a gateway to a lot of really hacky projects - I am not sure if it's really a good idea to make this information available to mods whatsoever, even in the UI scope. This could be used to detect loading a saved game, which I am really not a fan of.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: System time in ZScript

Post by NightFright »

I see. Was asking since the feature was/is somewhat available via hud_showtime for the ZDoom alternate HUD. I assume there's no way to tap into that via ZScript, either?
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: System time in ZScript

Post by Void Weaver »

So there is no way to use GetRealTime() from althud's DrawTime for ex.?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49225
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: System time in ZScript

Post by Graf Zahl »

It's deliberately declared private. Guess why... ;)

As a pure UI widget this is fine but as soon as this can be used to alter gameplay, it will become problematic. It cannot be on the 'play' side, because even Unix time stamps depend on the locally set time on each system so they would differ.

@Rachael: This value could be safely stored in a double, we don't need 64 bits ints just for that.
As for the savegame thing, there's already a ZScript and ACS event for that, so this wouldn't add much of a problem for that. The play synchronization issue is the biggest caveat here.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: System time in ZScript

Post by NightFright »

Well, I would just want to use it just like in the ZDoom HUD, simple display of system time onscreen. If you want to prevent it from doing anything else, that'd work for me.
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: System time in ZScript

Post by Rachael »

Well - I might come up with something then. It doesn't seem to difficult to implement. I'm going to force it to be UI-only though - if an author wants to pass the system time to the game sim, s/he can still use a NetEvent for that.

I'm probably going to put in a debug override for this, too, though - that way it would be possible to test certain dates (ie Christmas) without manipulating the actual system time.
User avatar
NightFright
Spotlight Team
Posts: 1379
Joined: Fri May 02, 2008 12:29 pm
Location: Germany

Re: System time in ZScript

Post by NightFright »

Excellent. Thanks a lot in advance, guys!
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: System time in ZScript

Post by Matt »

Would the debug override be accessible by the player to circumvent any savegame detection?
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: System time in ZScript

Post by Rachael »

The whole point of the debug override is to be accessible by the player - for any reason, whatsoever, and not strictly to circumvent anything.
Last edited by Rachael on Mon Sep 09, 2019 8:15 am, edited 2 times in total.
Reason: reworded, clarified
User avatar
phantombeta
Posts: 2162
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: System time in ZScript

Post by phantombeta »

As Graf said, I wouldn't worry about it being used for savegame detection. It would be extremely janky, and there's a far better way that isn't really fixable at all.

Semi-related:
@Graf What ACS event? I don't remember any such thing, and can't find it anywhere either O_o
User avatar
Rip and Tear
Posts: 186
Joined: Tue May 02, 2017 3:54 pm

Re: System time in ZScript

Post by Rip and Tear »

Rachael wrote:Only way this will happen is if it's UI-scope only. The game world is deterministic by nature and external influences (such as time) would ruin that.

I'm thinking the best way to implement this is to create and expose a UI element that can be accessed that gives a Unix timestamp only, and possibly a local timezone offset. Then, functions can be made to extend that element to internally determine the correct time from that timestamp.

Unfortunately, however, without access to 64-bit ints, such an implementation would be weak to the 32-bit timestamp overflow issue happening in 2038.

This however, sounds like a gateway to a lot of really hacky projects - I am not sure if it's really a good idea to make this information available to mods whatsoever, even in the UI scope. This could be used to detect loading a saved game, which I am really not a fan of.
Isn't it possible to detect savegames from the WorldLoaded event handler?
User avatar
Rachael
Posts: 13923
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: System time in ZScript

Post by Rachael »

Of course you respond to a really old post without looking at the further discussion :P
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”