Re: Several questions regarding Inform


31 Jul 1995 11:36:57 GMT

Christopher E. Forman <ceforma@rs6000.cmp.ilstu.edu> wrote:
> 1.) I'm a bit confused about creating a day/night cycle, to allow
> characters' houses to be closed and locked up for the night, and
> to create the need for food and sleep on the part of the player.

The relevant page of the manual is page 36. You set up the display of
time on the statusline with the declaration `Statusline time;' somewhere
near the start of your source, and you set up the passage of time with a
call to `SetTime(60 * hh + mm, rate)' in `Initialise', where the current
time is hh:mm on a 24-hour clock, and where you propose that time should
pass at `rate' minutes per turn (use a negative rate if you want rate
turns each minute).

Then, time progresses normally. If you want things to happen at
particular times of day, the you need to put code somewhere (the
`TimePasses' routine is best) to check for particular times of day and
act accordingly. If your game keeps track of the date, then you'll also
need to have a check for the time passing midnight. For example:

Global last_time = 0;
Global day = 0;

[ TimePasses h m;
! Check for time passing midnight
if (the_time < last_time) day ++;

! Convert the_time to hours, minutes
m = the_time ;
h = the_time / 60;

! Check for important times of day
if (h == 9 && m == 0) OpenTheShop();
if (h == 12 && m == 30) LunchTime();
if (h == 17 && m == 0) CloseTheShop();
];

> 2.) The game has a rather long introduction, so rather than make
> players repeatedly press <RETURN> to get to the prompt, I've
> decided to ask if a game should be restored before printing the
> intro. Is there a function in Inform that will allow a
> one-character (Y/N) response to be read from the keyboard, similar
> to the getch() or getche() functions in C?

See page 59 of the manual for a description of the `YesOrNo' function.
This requires the user to press return, so you may prefer the following:

[ YOrN r;
.yornstart;
@read_char 1 r;
if (r == 'y' or 'Y') rtrue;
if (r == 'n' or 'N') rfalse;
jump yornstart;
];

> 3.) I've currently got it set up so it's possible to "EXAMINE THE
> FOREST" in quite a few rooms in the game, but different responses
> are given for different rooms. I get the feeling that including a
> separate object definition for each occurrance of the forest is
> very inefficient, so I was considering doing something similar to
> the following:
>
> Object Forest "forest"
> with name "forest" "trees" "tree" "woods",
> description [;
> if (location == Room_1) "Description of forest for Room #1.";
> if (location == Room_2) "Description of forest for Room #2.";
> if (location == Room_3) "Description of forest for Room #3.";
> "Description of forest for Room #4.";
> ],
> found_in Room_1 Room_2 Room_3 Room_4,
> has scenery;
>
> Is this legal in Inform? (I'm still new at this, and just thought
> I'd ask before I go chopping up my existing code.)

This works fine. As a point of style the following code does the same
as your code but is more "object oriented":

Property forest_description;

Object Forest "forest"
has scenery
with name "forest" "trees" "tree" "woods",
description [;
print_ret (string) (parent(self).forest_description);
],
found_in Room_1 Room_2 Room_3 Room_4;

Object Room_1 "room 1"
with ...,
forest_description "Description of forest for Room #1.";

Object Room_3 "room 2"
with ...,
forest_description "Description of forest for Room #3.";

[etc]

> Also, can 'name' be defined in a similar manner? For example:
>
> Object Forest "forest"
> with name [;
> if (location == Pine_Forest) "forest" "trees" "pines";
> if (location == Oak_Forest) "forest" "trees" "oaks";
> ],

No, you can't do this; the `name' property cannot be a routine. If you
want the name of the forest to change from room to room you will need to
write a `parse_name' function (see chapter 15 of the Inform manual).
For example (in object-oriented style):

Property forest_word;

Object Forest "forest"
has scenery
with ...,
parse_name [ n w;
do {
k = 0;
w = NextWord();
if (w == 'forest' or 'trees' or (parent(self).forest_word)) {
k = 1; n++
}
} until (k == 0);
return n;
];

Object Room_1 "room 1"
with ...,
forest_name 'pines';

Object Room_2 "room 2"
with ...,
forest_name 'oaks';

> 4.) The manual's description for the property 'each_turn' states that it is
> active "each turn that the object is in scope, after all timers and
> daemons have run." Does this mean after they have run OUT, or just
> after the routines for each timer/daemon have been processed for that
> particular turn?

See page 36 of the manual for a description of what happens at the end
of the turn (your latter supposition is the correct one).

> 5.) What do you set the property 'article' to if you don't want an article
> printed at any time? (The object I'm working with here is 'your hammer,'
> and I want to avoid getting text like 'the your hammer' and 'a your
> hammer.')

In this case, the name of the object is "hammer" and the article is
"your". If you never want an article to appear (for example, if the
object is called "Steve"), give the object the attribute `proper'.

--
Gareth Rees