Inform and current time

I’m sorry if this is an stupid question, but I have been unable to find anything on it on my own. Does Inform 6 or Inform 7 have any ways of measuring how much time has passed in real time?

I have taken a look at Glulx Real Time by Erik Temple, but the whole extension seems a bit overwhelming for me, so I couldn’t understand it completely and using it seems a bit much for something that should be simpler. The extension is also not working perfectly in this exact situation.

For context, what I want to do is:

let startTime be the current time in milliseconds; [ although seconds would work, precision is always nice ] let duration be 6000; [or 6] while (current time - startTime) < duration: read a player's keypress; process that keypress; [ The mini-game itself is working fine, it's just the counting of time that's problematic ]

Currently, I’m using a number that varies called time elapsed and increasing it like so, using Erik Temple’s extension:

now Time elapsed is 0; let chron be chron for every 100 milliseconds up to duration times say "[@ increment time elapsed]"; [ do the things ] deactivate chron; stop virtualized timers;

The problem with this is that it seems that while keys are being pressed, the internal timers in Glulx (used in Erik Temple’s extension) stop working. So at best a player will be getting a few extra milliseconds or seconds at the whole event, but at worst the time taken for it will be much higher than it should have been. I had “countered” this by increasing the timer in .1 seconds for every two keypresses (which would not always be realistic and could even be worse - removing time from the player). So… Works, but non-ideal.

So, does Inform 7 (or 6) have any way of getting the current time in seconds or milliseconds? I am also using Glulx.

1 Like

The virtual machine will support it, but I don’t think there are currently any nice Inform 7 ways to access it. If you know Inform 6 it won’t be hard to make your own phrases, or if not then I or someone else should be able to help out in the next day or two. (Sorry I can’t help immediately)

Here are the functions for accessing the system clock:

1 Like

How is interpreter support for the system clock functions, though? Aren’t they fairly new?

1 Like

The test game is at . Gargoyle, WinG*, and Quixe support the functions. Zoom and Spatterlight do not.

1 Like

Thanks, zarf. That’s as good on support as we could ask for at this stage.

1 Like

This is exactly what I wanted!

I’m still getting the hang of inform 6 (and it’s somewhat overwhelming), but knowing what I have to use will put me in the right direction.

Also, searching for the function name on google led me to an extension on the inform 7 website that does exactly this. However, this extension is not listed in the Inform 7 website, although it’s accessible and can be downloaded. It only shows on google: Real Date and Time by Ron Newcomb. It included some inform 7 methods as:
what time is the player’s time (time)
what number is the player’s seconds (0 to 59)
what number is the player’s microseconds (0 to 999999)

Using it I could come up with:

let time be the player's time; let H be the hours part of time; let M be the minutes part of time; let currentSeconds be ((H * 60) + M) * 60; increase currentSeconds by the player's seconds; let milliseconds be (the player's microseconds / 1000); let currentMilliseconds be (currentSeconds * 1000) + milliseconds;

I’m guessing the lack of definitive support is why the extension is not listed?

Either way, I’ll be trying to understand how to use glk_current_time from reading Real Date and Time, since getting the milliseconds directly, rather than all those extra calculations, is probably a lot more efficient (and correct). If I can’t get it right, at least I have something that works! :smiley:

Thank you for the help.

Also noticed that in this way if a player is, for some reason or another, playing the game at midnight, the clock might… give them about 24 hours extra time to finish a mini-game. So:

[code]The First Day is a number that varies. The First day is 0.

[in the time code]
if the first day is 0:
now the first day is the player’s day;
otherwise if the first day is not the player’s day:
increase currentMilliseconds by (24 * 3600000);[/code]

This assumes a player wouldn’t play for more than a whole day, though.

1 Like

After studying Ron Newcomb’s extension I managed to make a function to return milliseconds and seconds.


[code]Include (-
Array countofseconds --> 3; ! this holds the number of microseconds elapsed since midnight on January 1, 1970, GMT/UTC

[ GetMilliseconds;
if (glk_gestalt(gestalt_DateTime, 0) == 0) return 0;
return (countofseconds–>1 * 1000) + (countofseconds–>2 / 1000);


[code]To decide which number is the/-- player’s current milliseconds:
(- GetMilliseconds() -).

To decide which number is the/-- player’s current seconds:
decide on (the player’s current milliseconds / 1000);[/code]

And to use (Example):

let startTime be the player's current milliseconds; let finishTime be startTime + (20 * 1000); [20 seconds] while the player's current milliseconds < finishTime: clear the main screen; say ((the player's current milliseconds minus startTime) divided by 1000); say "/"; say ((finishTime - startTime) / 1000); let input be key pressed in one frame;

So it all works now!

There is however something that confuses me about this Inform 6 code. At first I thought the “!” was something important, but turns out it’s just a comment. So I take it the “glk” function calls all Glulx functions and they happen to be unnamed? So “glk($0004, 20, 0) == 0)” means that the $0004 is calling “glk_gestalt_DateTime” and passing on the other variables? I tried replacing the glk call for the “glk_gestalt_DateTime” directly, but that didn’t compile.

So there’s no way to access these directly and we must instead use some internal number to mention them?

The only other code I used on inform 6 thus far were the simple things like “VM_KeyChar” and “VM_KeyDelay” which looked and worked like ordinary functions.

1 Like


There’s an I6 header file which defines them all as named functions: … p/infglk.h

Inform 7 includes this by default.

1 Like

Also, the comment “! glk_gestalt_DateTime(20, 0);” is written badly. That line of code is calling glk_gestalt(gestalt_DateTime, 0).

1 Like

Oh, I see. I have updated the code in my last post to reflect this - now it’s calling the pretty names directly and it compiles!

Thank you.

1 Like