I’m trying to make a clock that starts chiming on the hour and continues chiming once per turn for (hours part of the time of day) turns. This seems like it should be a simple task, but for some reason I’m having a lot of trouble getting it right. Here’s what I have currently:
[code]Chiming is a truth-state that varies. Chiming is usually false.
Every turn while chiming is true:
if the location is not indoors, say “‘BONG!’”;
The Tolling Bell is a recurring scene. The Tolling Bell begins when the minutes part of the time of day is 0. The Tolling Bell ends when chiming is false.
When the Tolling Bell begins:
if the location is not indoors, say “You hear the tolling of a distant bell. ‘BONG!’”;
[the first bong gets its own message, both so it can be more specific and because my every turn while chiming is true rule won’t take effect until the next turn]
let x be the remainder after dividing hours part of the time of day by 12;
if x is 0, now x is 12;
if x is not 1:
now chiming is true;
the clock stops chiming in x minus 2 turns from now;
At the time when the clock stops chiming:
now chiming is false.
[/code]
This seems to work as long as it’s not 1:00 or 2:00. At 1:00, I don’t want any more bongs after the initial one, so I’m not setting chiming to true. Unfortunately this seems to be causing the scene to end and then immediately start again in an infinite loop. I think the problem is stemming from the order that activities are processed.
In an ideal world, the code that I would like to work would be just:
[code]The Tolling Bell is a scene. The Tolling Bell begins when the minutes part of the time of day is 0. The Tolling Bell ends when the clock stops chiming.
Every turn during the Tolling Bell:
if the location is not indoors, say “BONG!”;
When the Tolling Bell begins:
now chiming is true;
if the location is not indoors, say “You hear the tolling of a distant bell. ‘BONG!’”;
let x be the remainder after dividing hours part of the time of day by 12;
if x is 0, now x is 12;
the clock stops chiming in x minus 1 turns from now;[/code]
But stopping 0 turns from now apparently doesn’t make it happen immediately, and Inform doesn’t accept “the clock stops chiming” as a condition for ending the scene, which is why I’m using the chiming truth-state, which is introducing problems because of the delay between toggling it and deciding whether to say “bong.”
I suspect there’s a much better way of doing this, but surprisingly I couldn’t find an example of this sort of thing in the documentation. Help!