Other Responses to Actions
|
So far we have concentrated on how you can customise the responses to actions on objects directly involved in those actions as direct or indirect object, and that will probably be the most common type of action customisation you'll perform. But there are other types of response we should look at for the sake of completeness.
If you want an object not directly involved in a command to respond to it, you can use beforeAction() or afterAction(). As their names suggest, the first of these responds to the action just before it's performed (i.e. just before the appropriate action routine is invoked) while afterAction() is called just after an action is performed. These two routines are called on every object that's in the actor's scope when the action is performed, but only if the command reaches the action stage (i.e. it hasn't already been ruled out by verify(), check(), or preCond). Thus, if you want another object to respond to an action that fails, you must make it fail in action, rather than before, e.g.
|
"Boy is she ugly! "
isHer = true
dobjFor(Kiss)
{
verify() { }
action()
{
reportFailure('You move your lips towards hers, but your
nerve fails you at the last moment. ');
}
}
;
|
"He looks a fine young man. "
isHim = true
isProperName = true
beforeAction()
{
if(gActionIs(Kiss) && gDobj == wickedWitch)
{
"<q>Hey, what do you think you\'re doing!</q> cries Bob,
grabbing you by the arm and pulling you back, <q>Don\'t you
know that kissing her will turn you into a lump of vile green
blancmange?</q> ";
exit;
}
}
;
|
|
"Hey, what do you think you're doing!" cries Bob, grabbing you by the arm and pulling you back, "Don't you know that kissing her will turn you into a lump of vile green blancmange?"
|
|
You move your lips towards hers, but your nerve fails you at the last moment.
|
|
{
if(gActionIs(Kiss) && gDobj == wickedWitch)
{
"<q>Wise decision</q> Bob approves, <q>I suppose you realize
that if you had gone ahead and kissed her you\'d have been
turned into a lump of vile green blancmange!</q> ";
}
}
|
|
"You cling precariously to the trunk, next to a firm, narrow branch."
down = clearing
enteringRoom(traveler)
{
if(!traveler.hasSeen(self) && traveler == gPlayerChar)
addToScore(1, 'reaching the top of the tree. ');
}
roomBeforeAction()
{
if(gActionIs(Jump))
failCheck('Not here -- you might fall to the ground and
hurt yourself. ');
}
roomAfterAction()
{
if(gActionIs(Yell))
"Your shout is lost on the breeze. ";
}
;
|
|
{
if(isTiedUp && !gActor.ofKind(SystemAction)
&& !gActionIn(Look, Inventory, Examine)
{
"You can't do that while you're tied up. ";
exit;
}
}
Getting Started in TADS 3
[Main]
[Previous] [Next]