Re: Pushing objects to other locations


17 Aug 95 23:23:58

searle@longacre.demon.co.uk (Michael Searle) wrote:

> I have a problem with pushing objects from one room to another, which may be
> a bug in Inform or the libraries as an identical error occurs using the
> demonstration Toyshop (not Magic Toyshop).
>
> In Toyshop, the little red car's description is not printed the turn after
> it has been pushed.

[snip]

> In my game, a crate can be pushed and also gives no description the turn
> after it is pushed.

[snip]

Well, it looks more like a design decision than an actual bug to me.
(Of course, the difference between these two can be rather fuzzy at
times. :-) If you look at AllowPushDir() in VerbLib, you will find
that the player is moved before the pushed object is.

What *does* look like a genuine bug (I've mailed Graham about it) is
that pushing an object into a dark room appears to move it to
'thedark' rathern than to the intended room.

However, I don't think all is lost ... I played around a bit with the
problem, and came up with a solution which I *think* will work, though
it will probably need more testing than I put into it. My idea was
using the NewRoom() function, which I think is called when a player
moves from one room to another, *before* the new room's description is
given. I've included the program, even though it got a bit longer than
I had hoped ...
_
Torbjorn Andersson

! This program should demonstrate how an object which is being pushed from
! one room to another can appear as soon as the player enters. Feel free to
! use it if you think it is a reasonable way of implementing it, but please
! note that I cannot guarantee anything.
!
! Also, note the subtle bug which happens when pushing the crate into a
! dark room: The crate will be moved to 'thedark' instead of the proper
! room. This seems to be a bug in the library (I have reported it to
! Graham, but I have not waited for his reply), and has nothing to do with
! the way this example is written.
! _
! Torbjorn Andersson, August 1995

Switches xdv5s;

Constant Story "THE TEST";
Constant Headline "^As it says, just a test.^";

Include "Parser";
Include "VerbLib";

! Since AllowPushDir() will move the player before moving the object, I use
! the variable 'push_dir' to keep track of which object is being pushed (I
! assume it is only possible to push one object at a time). This variable is
! set by the pushed object's 'before' routine.

Global push_object = 0;

! Just a few objects to test the idea in.

Object East_Hallway "East Hallway"
with description "You are at the east end of a long hallway.",
w_to West_Hallway;

Object West_Hallway "West Hallway"
with description "You are at the west end of a long hallway.",
e_to East_Hallway,
has light;

! This is, basically, the a simplified version of the little car from the
! Toyshop example. The main difference is that I set 'push_object' in the
! 'before' routine.
!
! Note that it is vitally important to reset 'push_object' after calling
! AllowPushDir(), because otherwise, if AllowPushDir() fails to move the
! player, 'push_object' would still be set and would be used in NextRoom()
! the next time the player moves, even if he isn't trying to push the
! crate this time.

Nearby crate "wooden crate"
with name "large" "crate" "wooden",
description "Not large enough to sit in, but too heavy to carry.",
before
[;
PushDir:
push_object = self;
AllowPushDir();
push_object = 0;
rtrue;
],
has static container open;

Nearby light_source "light source"
with name "light" "source",
description "Just a source of light.",
has light;

! The NewRoom() function is called when a player moves from one room to
! another. Usually, it is just a #Stub in Grammar.h
!
! My first idea was to move 'push_object' to 'real_location' instead, but
! for some reason which I haven't bothered to find out yet, 'real_location'
! always seems to be 'thedark' here. Anyway, if the player is moving into a
! dark room, the crate won't be visible anyway, so that is left for
! AllowPushDir() to handle.

[ NewRoom;
if (push_object ~= 0) {
print "You bring ", (the) push_object, " with you into ",
(the) location, ".^";
if (location ~= thedark)
move push_object to location;
}
];

[ Initialise;
print "^^^^Wellcome to ...^^";
location = West_Hallway;
lookmode = 2; ! Verbose
];

Include "Grammar";

end;