Use the `number' grammar token and the `special_number variable on the
one hand, and the `special' grammar token, and the `special_word'
variable on the other. For example,
Verb "login" * number -> Login;
Verb "password" * special -> Password;
Object computer "computer"
has static
with number 0,
description [;
CDefArt(self); print " is now displaying ";
if (self.number == 0) "~Login:~";
if (self.number == 1) "~Password:~";
"~blah blah blah...~";
],
before [;
Login:
if (self.number ~= 0)
"You can only do that at a login prompt.";
print "You enter the login name. ";
self.number = 1;
if (special_number == 157) give self general;
<<Examine self>>;
Password:
if (self.number ~= 1)
"You can only do that at a password prompt.";
print "You enter the password. ";
if (special_word == 'foo' && self has general)
self.number = 2;
else {
self.number = 0;
print "The computer displays ~Login incorrect~. ";
}
give self ~general;
<<Examine self>>;
],
...
> Second problem: I have a cupboard which is mentioned in the room
> description and should print out a message only if it's actually
> open and there is something inside it. If I put this in the
> initial property, the library insists on printing a new_line
> every time the cupboard is closed. Same thing happens if I use
> the when_open property, even if I don't use when_closed at all.
Use the `describe' property, e.g.
Object cupboard "cupboard"
with describe [;
if (children(self) > 0 && self has open) {
new_line; <<Search self>>;
}
rtrue; ! prevent any description appearing if closed
],
...
> (BTW, there seems to be a slightly inconsistent behaviour of the
> initial property anyway, as it will not print out anything if if
> defined in an object with the switchable attribute set.)
An object with the `switchable' attribute set shouldn't use `initial'
but instead should use the `when_on' and `when_off' properties.
However, `initial' is aliased to `when_on', so if you use it, you get
the effect of using `when_on' without a corresponding `when_off'.
-- Gareth Rees
-- Gareth Rees