Re: Tricky objects in Inform.....


26 Apr 1995 11:52:05 GMT

The best place to post queries about *writing* (as opposed to playing)
interactive fiction is the newsgroup rec.arts.int-fiction. I've set
followups to that group.

Paul Bowler <Paul@mdown.demon.co.uk> wrote:
> The briefcase has to be able to hold things, but at the same time
> supports a lock. The problem I have is that an object cannot be both
> a container and supporter at the same time.

One way to do this is to use the "add_to_scope" property (you'll need to
have release 5/6 or later of the Inform library). Read item 14 of the
"library history" file, which is available on the Web at:

http://www.cl.cam.ac.uk/users/gdr11/inform/library-history.html

or by FTP from ftp.gmd.de (in /if-archive/programming/inform/library/).
You'd make the briefcase a "container" and use the "add_to_scope"
property to put the lock into scope whenever the briefcase is.

However, a better solution would be to abandon the idea of a separate
object to represent the lock, and just use "lock" as a synonym for
"briefcase". Thus the player can type "unlock briefcase" rather than
the less natural "unlock lock"!

> The second problem concerns the lock itself. It is a combination lock
> consisting of three rotating number wheels, each with numbers from
> 0 to 9. I wish the player to be able to use commands such as:
>
> move lock to 123
> or turn lock to 246
> or set lock to 369

Careful reading of Grammar.h is necessary to decide exactly how to
extend the various verbs, but I recommend something like:

Object Briefcase
has container openable locked
with name "briefcase" "brief" "case",
description [;
print "... The combination lock is currently set to ";
print_number self.number;
".";
],
capacity 5,
number 0,
before [;
Close:
if (self.number ~= 256) {
give self locked ~open;
"The lock catches.";
}
SetTo:
if (special_number < 0 || special_number > 1000)
"The combination lock only has three digits.";
self.number = special_number;
if (special_number == 256) give self ~locked;
else if (self hasnt open) give self locked;
];

[ SetToSub; "I don't see how to do that."; ];

Extend "move" first * noun "to" number -> SetTo;
Extend "turn" first * noun "to" number -> SetTo;
Verb "set" * noun "to" number -> SetTo;

> Finally, I want the player to be behind a window, but still be able
> to see and examine objects at the other side without defining them as
> being in both places.

You can use the "add_to_scope" property to put the relevant objects in
scope (see item 24 of the library history). For example:

Object Window "window"
with add_to_scope [ i;
! You may need to improve this if there are any open
! containers in OtherRoom whose contents you want to be
! in scope:
objectloop (i in OtherRoom)
AddToScope(i);
],
before [;
Search:
! This action is generated by `look through window', so
! describe OtherRoom somehow
],
...

You'll also want to prevent the player from doing anything other than
examining objects that are seen through the window. So you could create
a `before' routine for the room with the window:

Object ThisRoom "This Room"
with before [;
if (action ~= ##Examine &&
((noun ~= nothing && noun in OtherRoom) ||
(second ~= nothing && second in OtherRoom)))
"The window is in the way.";
],
...

Hope this helps. E-mail me if you have any questions.

--
Gareth Rees