Yes. The variable verb_word is set to the dictionary word determined to
be the verb of the sentence, so if in your object you trap the Enter
action and test the value of verb_word, you can differentiate between
these actions:
before [;
Enter: if (verb_word == 'sit') {
...
} elseif (verb_word == 'stand') {
...
} else {
...
}
], ...
--
Alex Watson
http://www.zen24203.zen.co.uk/
Emails to alexwatson at froup dot com, not deadspam.
> ...
> } elseif (verb_word == 'stand') {
> ...
I'm doubting myself now. It's been so long since I've used Inform
seriously. Does it have actually have an elseif? I seem to recall it had
to be phrased as else if or something instead.
You pretty much have to look at verb_word. You may not want to trust my
solutions, but perhaps something like:
Global player_posture;
Object Transmat "transmat" LightRoom
with description "A large platform for matter transmission.",
name 'transmat' 'transmitt' 'matter',
before [; Enter:
if (verb_word=='sit') {
player_posture='sit'; ! possible optional state variable
}
if (verb_word=='lie') {
player_posture='lie';
print "As soon as you lie on the transmat, you are whisked
(whisk, whisk) off to somewhere else.^^";
PlayerTo(CryogenicPod);
rtrue;
}
],
has scenery enterable supporter;
HTH
CK
'stand'... why did I think Drakore said 'lie'?
>> ...
>
> I'm doubting myself now. It's been so long since I've used Inform
> seriously. Does it have actually have an elseif?
No.
> I seem to recall
> it had to be phrased as else if or something instead.
Yes, usually 'else if'. In this example you may not need 'else', since
the two conditions are mutually exclusive.
CK
>> I'm doubting myself now. It's been so long since I've used Inform
>> seriously. Does it have actually have an elseif?
>
> No.
>
>> I seem to recall
>> it had to be phrased as else if or something instead.
>
> Yes, usually 'else if'. In this example you may not need 'else', since
> the two conditions are mutually exclusive.
In the original example I used it because I then added the else portion
for when the verb was neither sit nor stand, which I think might not work
with "else if" (would it take the negation of the whole if, else if
or just the last if?)
Right, and we certainly can't assume each block does a return (although
if it does you don't need the following 'else'). I keep thinking I've
read stuff correctly, and then realising I haven't....
If I understand your last question correctly, 'last if' (unless you add
braces). But still:
if (a) {;}
else if (b) {;}
else if (c) {;}
else {d()}
of course runs d() iff ¬(a | b | c). It is more confusing if you have
if (a)
if (b) {;}
else if (c) {;}
else {d()}
so I try not to do it, or use braces.
CK
I think this topic is sufficiently tricky to warrant an entry in
the Inform FAQ. My suggested code is as follows; before I
write it up, I'd be pleased to hear of any comments and
improvements.
Object -> sofa "sofa"
with name 'sofa' 'seat',
description "It's a pretty regular sofa.",
sit_or_lie false,
before [;
Enter:
if (verb_word == 'sit' or 'lie') {
if (parent(player) == self && self.sit_or_lie == verb_word)
return L__M(##Enter,1,noun);
move player to noun;
self.sit_or_lie = verb_word;
if (AfterRoutines() || keep_silent) rtrue;
if (verb_word == 'sit')
"You sit on ", (the) self, ".";
else
"You lie on ", (the) self, ".";
}
else {
if (parent(player) == self && self.sit_or_lie == false)
return L__M(##Enter,1,noun);
move player to noun;
self.sit_or_lie = false;
if (AfterRoutines() || keep_silent) rtrue;
"You stand on ", (the) self, ".";
}
],
react_before [;
Exit:
if (parent(player) ~= self) rfalse;
move player to parent(self);
if (AfterRoutines() || keep_silent) rtrue;
if (self.sit_or_lie) {
self.sit_or_lie = false;
"You stand up.";
}
else
"You climb off ", (the) self, ".";
],
has supporter;
Cheers, Roger
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
You'll find my Cloak of Darkness, Parsifal, Informary
and more at http://www.firthworks.com/roger/
> I think this topic is sufficiently tricky to warrant an entry in
> the Inform FAQ. My suggested code is as follows; before I
> write it up, I'd be pleased to hear of any comments and
> improvements.
<snipped verb_word code>
No one seems to have mentioned this, so I will: might it be better
to use "Extend replace" to redefine the grammar so that Sit and Stand
actually map to two different actions? The new SitSub and StandSub
could redirect with <<Enter noun>>, so the normal behavior would be the
same as it is now, but you'd be able to trap the different actions
individually.
--
--OKB (not okblacke)
"Do not follow where the path may lead. Go, instead, where there is
no path, and leave a trail."
--author unknown
That's a fair question. The result then looks something like this;
technically cleaner perhaps, but rather longer overall.
Object -> bed "bed"
with name 'bed',
description "It's a pretty regular bed.",
sit_or_lie false,
before [;
Enter,StandOn:
if (parent(player) == self && self.sit_or_lie == false)
return L__M(##Enter,1,self);
move player to self;
self.sit_or_lie = false;
if (AfterRoutines() || keep_silent) rtrue;
"You stand on ", (the) self, ".";
SitOn:
if (parent(player) == self && self.sit_or_lie == action)
return L__M(##Enter,1,self);
move player to self;
self.sit_or_lie = action;
if (AfterRoutines() || keep_silent) rtrue;
"You sit on ", (the) self, ".";
LieOn:
if (parent(player) == self && self.sit_or_lie == action)
return L__M(##Enter,1,self);
move player to self;
self.sit_or_lie = action;
if (AfterRoutines() || keep_silent) rtrue;
"You lie on ", (the) self, ".";
],
react_before [;
Exit:
if (parent(player) ~= self) rfalse;
move player to parent(self);
if (AfterRoutines() || keep_silent) rtrue;
if (self.sit_or_lie) {
self.sit_or_lie = false;
"You stand up.";
}
else
"You climb off ", (the) self, ".";
],
has supporter;
[ SitOnSub; <<Enter noun>>; ];
Extend only 'sit' replace
* 'on' 'top' 'of' noun -> SitOn
* 'on'/'in'/'inside' noun -> SitOn;
[ LieOnSub; <<Enter noun>>; ];
Extend 'lie' replace
* 'on' 'top' 'of' noun -> LieOn
* 'on'/'in'/'inside' noun -> LieOn;
[ StandOnSub; <<Enter noun>>; ];
Extend 'stand' replace
* -> Exit
* 'up' -> Exit
* 'on' 'top' 'of' noun -> StandOn
* 'on' noun -> StandOn;
I myself had thought of that solution before reading any replies. But I kept
silent because looking at verb_word seemed to work sufficiently well.
Anyway, I second OKB's suggestion; it's an (at least) equally good method.
--
| Email: Daniel Dawson <ddawson at icehouse.net> ifMUD: DanDawson |
| Web: http://www.icehouse.net/ddawson/ X-Blank: intentionally blank |
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
change grammar.h as follows:
original grammar.h entries
Verb 'stand' * -> Exit
* 'up' -> Exit
* 'on' noun -> Enter;
Verb 'sit' 'lie'
* 'on' 'top' 'of' noun -> Enter
* 'on'/'in'/'inside' noun -> Enter;
***************************************
Modify to:
Verb 'lie'
* 'on' 'top' 'of' noun -> Lie
* 'on'/'in'/'inside'/'under' noun -> Lie;
Verb 'sit' * 'on'/'in'/'inside'/'under' noun -> Sit;
Verb 'stand' * -> Exit
* 'up' -> Stand
* 'on'/'in'/'inside'/'under' noun -> Stand;
Of course you will have to place subroutines in your code
for the appropriate verbs as well.
NOOO! Don't change the library itself. Just leave it alone and put 'Extend
replace' stuff in your own code, as OKB suggests. Similar thing if you want to
change a library routine: just use a 'Replace' directive before including the
library file it's in, then write your own.
>Verb 'stand' * -> Exit
> * 'up' -> Stand
> * 'on'/'in'/'inside'/'under' noun -> Stand;
BTW, what about
* 'on' 'top' 'of' -> Stand
That makes sense to me as well.
One more issue. Suppose the player wants to sit down in a place where there is no chair.
It would be reasonable if >SIT were to cause the player to sit on the ground. If a chair
is present, it should be preferred, but the player should still be able to >SIT ON THE
GROUND if e likes. (Warning: the following code contains Platypusisms. Most of them should
be pretty straightforward, but note that the "disambiguate" property works as a per object
ChooseObjects.)
Object Ground "ground"
has static concealed supporter,
with
name 'floor' 'ground',
found_in [; rtrue; ],
allow_entry
[way_of_entry;
if (way_of_entry == upon) rtrue;
],
meddle_early[;
Exit: if ((actor.posture == SITTING) &&
(parent(actor) == actor.location))
<<Stand>>;
else rfalse;
],
respond_early[;
EnterOn: actor.posture = SITTING;
"You sit on the ground.";
],
respond_early_indirect[;
PutOn: <<Drop noun>>;
],
disambiguate
[code;
if (code == 2)
{
if (action_to_be == ##EnterOn)
return 4; ! The ground likes to be sat on a little.
}
];
And here is a chair:
Object Chair "Throne of The High Kings" ThroneRoom
has supporter,
with name 'chair',
allow_entry
[way_of_entry;
if (way_of_entry == upon) rtrue;
],
description "It's an awfully impressive throne.",
disambiguate
[code;
if (code == 2)
{
if (action_to_be == ##EnterOn)
return 7; ! The chair likes to be sat on more than the ground does.
}
];
A couple of other notes:
Although grammarwise, the ground should act like any other supporter one might sit or put
things on, it would be unnecessary and confusing to have things on top of it, since
anything in the room sort of defaults to being thought of as being on the ground, and
since allowing one to put stuff on a floating object is probably a bad idea.
I have made the player's posture a property of the player object rather than of the thing
sat on. This allows the PC and any number of NPCs to lie or sit on a bed together. (What
they do next is thankfully beyond the scope of this thread.)
**Owen