# Question About Scheduling Scenes Using Time of Day

So, I wanted to schedule scenes to start at certain times of day as well as other changes (moving props around mostly) but ran into a snag.

It seems like if I say “Scene Whatever begins when the time of day is 8:00 AM”, that scene will only begin if it is exactly 8:00 AM.
Meaning, if I have things set up so every action the player can take advances the clock by exactly one minute, as is the case by default, there’s no problem. But if I’ve got actions that take odd number of minutes, the scene may never start because the player skipped from 7:59 to 8:02.

Is there a phrasing that will let me trigger a scene or event at any time between a specified start and stop time? If not, I’d be grateful for ideas for a workaround.

Thanks.

Would timing your scenes by a number of turns be a workaround?

One good way to avoid scheduling difficulties of this sort is not to set the time of day directly. If you want to advance time forward several minutes, use a loop of some sort to call “the advance time rule” multiple times.

In this case, unfortunately, I’m trying have certain events occur at fixed times in the world, while the player can take actions that in a single turn that might take up a large amount of time or a small amount of time. Ideally, these would be things that occur whether or not the player is directly there to observe them.

Oh, this sounds promising. I had been using a formula borrowed from the inform recipe book – the example given is “Endurance”, which directly changes the time of day based on action the player has taken.

Hmm. I gave this a try – knocked off from the inform recipe book, but substituting while loop that causes the advance time rule to be called for each individual minute an action takes, but no luck. The time advances perfectly, but scheduled scenes still won’t trigger unless the player has a turn end on the exact right minute. Any idea of what I’m doing wrong?

[code]
Work duration is a number that varies.

Every turn:
follow the time allotment rules;
while work duration is greater than 1:
follow the advance time rule;
now work duration is work duration - 1.

The time allotment rules are a rulebook.

A time allotment rule for examining or looking:
now work duration is -1;
rule succeeds.

A time allotment rule for going:
now work duration is 2;
rule succeeds.

A time allotment rule for going up:
now work duration is 5;
rule succeeds.

A time allotment rule for waiting:
now work duration is 10;
rule succeeds.[/code]

My fault–the advance time rule doesn’t trigger scene changes. Use “follow the turn sequence rules” instead.

A good example to look at here might be “Nine AM Appointment”, which includes a variant of the “waiting” action that lasts however long the player wants.

Ah, okay, that seems to have done the trick – but now I see a bit of a catch.

It looks like using “follow turn sequence rules” in this way means that anything triggered by an “every turn” rule will repeat for every minute that passes.

That’s actually pretty useful for some stuff happening behind the scenes, but anything involving “say” statements will print a dozen times if an action takes 12 minutes, which may be a dealbreaker.

It’s been a while since I’ve attempted to muck with the standard rules (and actually I apparently can’t even figure out where to find them to look at them, sheesh) but I suppose one could probably do something involving listing and unlisting the every turn rules listed in the follow turn sequence rulebook? But not entirely sure how I’d pull that off.

You could use Text Capture by Eric Eve to prevent any text from printing during that time, I suppose. Begin text capture before following the turn sequence rule book, then turn it off afterward.

Ah, this is perfect! Thank you.

I ended up with a few ideas about how to approach the last issue, but using text capture was much simpler and did the trick with just two more lines, like so:

``` After extended behavior: start capturing text; follow the time allotment rules; while work duration is greater than 1: follow the turn sequence rules; now work duration is work duration - 1; stop capturing text; continue the action. ```

Still prints any “every turn” text once because the standard rules already follow the turn sequence rules once, which is entirely ideal.

Thank you so much for the help; it would have taken me much longer to puzzle through myself.

No problem!

One caveat: if an “every turn” rule uses Text Capture itself for some reason, it will most likely turn it off again afterward, letting the text from other rules print out.

Sounds like you have a plan for modifying your code, but if you need them for future reference, the Standard Rules are listed as an extension by Graham Nelson. You can open them with File > Open Extension > Graham Nelson > Standard Rules.

I’m using that “work duration” code, for the action “sleeping,” but it gives me an error – something about a “stack overflow.”

[code]Work duration is a number that varies.

Every turn:
follow the time allotment rules;
while work duration is greater than 1:
follow the turn sequence rules;
now work duration is work duration - 1.

The time allotment rules are a rulebook.

A time allotment rule for sleeping:
now work duration is 20;
rule succeeds.[/code]

The problem is that the turn sequence rules call the every turn rules, so your code keeps calling itself ad infinitum. Eventually the call stack gets too big and it gives the error you saw.

Would you know how to stop Inform7 from calling on itself like that?