I’m busy trying to get an NPC to be somewhere for a predictable period of each day. However, I noticed it wasn’t working well. During testing, I find that at midnight on the first day of gameplay, the time count in my scenes messes up and flips to negative numbers! Is this expected behavior? Am I doing something seriously wrong? This is using glulx. Here’s what I see starting around 11:58pm, using ‘scenes’. I find that my scenes stop working (don’t end, don’t begin, etc.) after this happens, breaking my game.
The time since a given scene began is calculated by first noting what in-game time of day it is currently and then subtracting the time when the scene began from it.
So, if it’s currently 1 PM (780 mins past midnight) and the scene began at 12 PM (720 mins past midnight), the scene has been going on for 60 mins. (As you know, Inform internally measures time in ‘minutes’.)
But at 12 AM the time of day is reset (to 0 mins past midnight), and that’s where you start getting negative numbers (since 12 AM minus 12 PM equals 0 minutes minus 720 minutes, i.e. -720 mins).
Ah, OK. So do I need to start doing math gymnastics to keep my cycling scenes working, then? (I have a train system which operates on 'scene station ends xxx mins after it begins, scene enroute begins after station ends, etc.). e.g. use an event to end the scene rather than just turn math? Also, I had just put in an ‘At 2:00 pm’ rule (not scene start, event sequence) and I don’t see it fire that second day. Is this likely related, or is it likely something else?
No, that is because events ever happen only once. If you want to make an event happen again, you have to reschedule it manually.
Note also that if the game takes a jump in time and so skips the time of day when an event is scheduled to happen, the event will still happen as soon as possible for 30 minutes after the scheduled time. That means you can’t reset the event to happen again at a certain time of day during that half of an in-game hour or it would happen again immediately.
(This is documented in Appendix B, but I’m not sure it’s in the built-in docs.)
Short of hacking the I6 Templates, I think you have to do something like this:
[code]When play begins: time is ripe at 2:00 PM.
At the time when time is ripe:
say “Time is ripe.”;
time is ripe again at 2:30 PM.
At the time when time is ripe again: time is ripe at 2:00 PM.[/code]
Ahhh, I see. Thank you much. I have some kludging to do ,then.
You can also use Every Turn rules:
Every turn when the Time of Day is 2:OO PM:
I think this should also work:
Catching the train is a recurring scene. Catching the train begins when the time of day is 7:54 AM.
capmikee: Yep, thanks, I could use those. The problem is that my two scenes are continuously ongoing. I’m doing something much like the Empire Builder train example, but making a constantly-running subway that goes in a loop. So changing scenes with specific times of day is both a) onerous (zillions of start/stop lines) and b) leaves me open to weird breakages as it doesn’t guarantee that only one scene is running at a time.
This is getting really twisted in my head. :-/ I tried defining the length of a scene using turns since I presume the turn count never goes negative, but I can’t get Inform to accept any conditions written using turns (“Scene A ends when Scene A has been playing for x turns” gives an error).
So it seems my problem is that a set of recurring scenes which start when each other end, and whose duration are determined by time, will always break at midnight. Still don’t have a solution for this. I tried hacking it so that either scene will end ‘hackily’ if the time is 11:59 pm, but then I run into the problem of starting up again - you can only start up a scene based on one condition that doesn’t involve other scene triggers, and I already start the whole cycle using a turn condition to kick things off.
How about using a simple toggle value?
[code]There is room. Scenester is a truth state that varies.
Scene A is a recurring scene. Scene B is a recurring scene.
Scene A begins when play begins.
When Scene A begins: Switch A-B in 2 turns from now.
At the time when Switch A-B:
if scenester is true, now scenester is false;
otherwise now scenester is true;
Switch A-B in 2 turns from now.
Scene B begins when scenester is true.
Scene B ends when scenester is false.
Scene A begins when Scene B ends.
Scene A ends when scenester is true.[/code]I’ve tested this a little and it seems to handle the midnight switchover without breaking.
That’s an interesting idea, which I shall go test. I did make my situation work by changing my scene start/end conditions using the following:
sceneTurn is a number that varies. Scene A is a recurring scene. Scene A starts when the turn count is 3. Scene A starts when Scene B ends. When Scene A starts: now sceneTurn is turn count + 3; <stuff to start scene> Scene A ends when turn count is sceneTurn. Scene B is a recurring scene. Scene B starts when Scene A ends. When Scene B starts: now sceneTurn is turn count + 3; <stuff to start scene> Scene B ends when turn count is sceneTurn.
This avoids the whole ‘clock math’ problem which results in the negative numbers. It works for me because my game uses rigid 1 minute turns. Well…it does as far as I can tell. I was prepared to have to use separate counters, one for each scene, but using the same counter seems to work fine in testing.
I think Zarf defined a phrase something like this:
To decide whether a cycle of (period - a number) turns starting at (offset - a number) is repeating:
if the turn count is less than offset, no;
Let the adjusted count be the turn count minus the offset;
Decide on whether or not the remainder after dividing the adjusted count by the period is zero.