Game Clock as Generalized Time Periods (new I7 coder)

After much internet browsing and searching, I haven’t found an example which is close to what I’m attempting. I’m not really much of one for forum boards, but I’m getting desperate. I’m very new to I7 and want to learn. So here goes…

I am attempting to write a section in my game which tracks the “time of day” as a general time period, based on the game clock’s current time of day. The best way I could think of to do this, was to make a table. Unfortunately, no matter which way I write my code, it gives me an error, basically telling me, I’m an idiot for even trying. :confused:

What am I doing wrong? :open_mouth:
Here’s what I have so far (You can cut and paste into I7 and you’ll see my most frequent error:

“Time Project”

The Test Module is a room.

A time period is a kind of value. The time periods are defined by the Table of Apparent Time. The current time period is a time period that varies. The current time period is early morning.

Table of Apparent Time
time period start time
early morning 4:00 AM
dawn 6:00 AM
morning 7:00 AM
mid-morning 9:00 AM
mid-day 11:00 AM
afternoon 1:00 PM
mid-afternoon 3:00 PM
early evening 5:00 PM
dusk 7:00 PM
evening 9:00 PM
night 11:00 PM
late night 2:00 AM

Time-checking is an action applying to nothing.

Understand “check time” and “time” as time-checking.

To say apparent time:
if there is a start time of time of day in the Table of Apparent Time,
choose a row with a start time of time of day in the Table of Apparent Time;
now the current time period is the time period entry;
say “It feels around [current time period].”

Report time-checking:
say “[apparent time]”

test with “check time”.

The recipe book has a chapter on time. There is an example of using named time periods, The Hang of Thursdays.

What error are you getting? If you copy the error that the above code is giving you then that would make it easier to figure out.

One thing about posting code is that the forum will wipe out your tab stops unless you paste your code into code tags. Hit the “code” button above the text box you’re typing in and paste your code in the resulting tags. (If you’re typing a reply at the bottom of a thread, hit “full editor” to reveal those formatting buttons.) This can make it a lot easier to read your code – especially with a table, which is nothing but tab stops.

Inform gets confused by all the different names with the word ‘time’ in them. Use the syntax ‘start time column’ rather than mere ‘start time’, and Inform will understand you.

But, as it is, your say phrase will still only change the current time period if you say the apparent time exactly at a start time! The current time period won’t be set correctly if you say the apparent time at, e.g., 12:34 PM.

So, try something like this:

[code]
Time-checking is an action applying to nothing.
Carry out time-checking: check time.
Report time-checking: say “It feels around [the current time period].”
Understand “check time” and “time” as time-checking.

To check time:
repeat through the Table of Apparent Time:
unless the time of day is before the start time entry, now the current time period is the time period entry.
[/code]That will also allow you to write conditions like Every turn when the current time period is evening: say "You start feeling sleepy."

That repeat code is brilliant, Felix. Thank you all so very much for your help. And your timely responses. I didn’t expect to hear back so soon.

Oops, sorry – the above code will let you write conditions like that, but they will only work as expected if you did a ‘check time’ earlier in the same turn. That’s no good of course. (My bad.)

What I ought to have suggested is this:

Time-checking is an action applying to nothing.
Report time-checking: say "It feels around [the current time period]."
Understand "check time" and "time" as time-checking.
      
To decide what time period is the current time period:
	let T be a time period;
	repeat through the Table of Apparent Time:
		unless the time of day is before the start time entry, now T is the time period entry;
	decide on T.

That actually updates the current time period whenever you test it, which is what you want.

Thanks again, Felix. I tried both suggestions. You were right. The second version is quite perfect.

The purpose was to create an “eyeball” guess for when a player has no watch. Adding the recipe regarding wait control, I hacked up a working example to illustrate. If anyone else finds this helpful or useful, I’m happy to share. :slight_smile:

[code]“Time Control” by Paige Fox

The Test Module is a room. The Waiting Area is south of the Test Module. A clock is in the Test Module. The clock is fixed in place.

A timepiece is a kind of thing.

A watch is a portable timepiece. A clock is a timepiece.

The player wears a watch. The player is in the Waiting Area.

A general time is a kind of value. The general times are defined by the Table of Apparent Time.

Table of Apparent Time
general time start time
early morning 4:00 AM
dawn 6:00 AM
morning 7:00 AM
mid-morning 9:00 AM
mid-day 11:00 AM
afternoon 1:00 PM
mid-afternoon 3:00 PM
early evening 5:00 PM
dusk 7:00 PM
evening 9:00 PM
night 11:00 PM
late night 2:00 AM

Time-checking is an action applying to nothing.

Report time-checking:
if no timepiece is visible,
say “It feels about [the current general time].” instead;
otherwise say “The time is [time of day + 1 minute].”

Understand “check time” and “time” as time-checking.

To decide what general time is the current general time:
let T be a general time;
repeat through the Table of Apparent Time:
unless the time of day is before the start time entry, now T is the general time entry;
decide on T.

Waiting more is an action applying to one number.

Understand “wait [a time period]” or “wait for [a time period]” or “wait for a/an [a time period]” or “wait a/an [a time period]” as waiting more.

Carry out waiting more:
let the target time be the time of day plus the time understood;
decrease the target time by one minute;
while the time of day is not the target time:
follow the turn sequence rules.

Check waiting more:
if the time understood is greater than 4 hours, say “You really don’t feel like waiting around that long.” instead.

Report waiting more:
say “You wait…”

Test me with “check time / n / drop watch / s / time / wait 3 hours / check time / n / time”[/code]

(And thanks matt w for the tip on forum formatting. :wink: )

Glad we could help!

One thing you might also want to do is make it so the current general time always tracks, well, the current general time, instead of getting reset whenever the player checks the time. You can do this by omitting the global variable “the current general time” and using a to decide phrase:

To decide which general time is the current general time: repeat through the Table of Apparent Time: unless the time of day is before the start time entry, decide on the general time entry.

Then you can delete “The current general time is a general time that varies.” and the Carry out time-checking rule and the “To check time:” rule, but you can still use “current general time” in other contexts.

(At least, I think; I haven’t tested the code, which is always hazardous.)

EDIT: Derp, somehow I overlooked that Felix had posted the exact same thing.

Yup. :smiley: Got a full working example posted above. You guys are awesome.

Yes. In this case that phrase decides on the first and earliest general time that is not before the time of day, whereas we want to find the last and latest. But you can fix that by having the phrase repeat through the table from bottom to top instead:

To decide what general time is the current general time: repeat through the Table of Apparent Time in reverse order: unless the time of day is before the start time entry, decide on the general time entry.(And that, I admit, is much more elegant than my previous suggestion of resetting a local variable over and over again as long as the loop lasts and then return its eventual vaule.)

The game Arthur uses something like this.