TADS3/adv3 provides a bunch of convenience methods and other semantic sugar for dealing with verify results from within action handlers on objects. But there doesn’t appear to be anything comparable for doing checks in the action declaration itself (as needs to be done for intransitive verbs).
Part of the problem is that all of the macros available for use in dobjFor() { verify() {} }
(logical
, illogical
, illogicalNow
, and so on) are doing something like a gVerifyResults.addResult()
under the hood. gVerifyResults
in turn is a macro that points to libGlobal.curVerifyResults
, and libGlobal.curVerifyResults
isn’t defined when Action.verifyAction()
is called.
So Action.verifyAction()
can’t use logical
, illogical
, and so on.
The cleanest thing that I could figure out to do is to add a method to Action
like:
modify Action
appendIllogicalResult(resultSoFar, msg) {
if(resultSoFar == nil)
resultSoFar = new VerifyResultList();
resultSoFar.addResult(new IllogicalVerifyResult(msg));
return(resultSoFar);
}
;
Then in an Action
definition you can write verifyAction()
using something like:
verifyAction() {
local result;
result = inherited();
if([SOME CONDITION YOU WANT TO CHECK])
result = appendIllogicalResult(result, '[YOUR FAILURE MESSAGE]');
return(result);
}
This works, but it’s still a bit of a mess compared to the way most action handlers on objects declare their verify()
methods.
Basically just looking for a cleaner/neater way to do this.
Here’s a simple demo that illustrates the above. It defines a new action for twiddling one’s thumbs, >TWIDDLE
, and a couple NPCs to try ordering to do it:
#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>
modify playerActionMessages
wontTwiddle = '{You/he} refuse{s} to twiddle {its/her} thumbs. '
;
modify Action
appendIllogicalResult(resultSoFar, msg) {
if(resultSoFar == nil)
resultSoFar = new VerifyResultList();
resultSoFar.addResult(new IllogicalVerifyResult(msg));
return(resultSoFar);
}
;
DefineIAction(Twiddle)
verifyAction() {
local result;
result = inherited();
if(!gActor.ofKind(TwiddleActor))
result = appendIllogicalResult(result, &wontTwiddle);
return(result);
}
execAction() {
defaultReport('{You/he} twiddle{s} {its/her} thumbs. ');
}
;
VerbRule(Twiddle) 'twiddle' : TwiddleAction verbPhrase = 'twiddle/twiddling';
modify Actor
obeyCommand(fromActor, action) {
if(action.ofKind(TwiddleAction))
return(true);
return(inherited(fromActor, action));
}
;
class TwiddleActor: Actor, Person;
startRoom: Room 'Void'
"This is a featureless void. "
;
+me: TwiddleActor;
+alice: TwiddleActor 'Alice' 'Alice'
"She looks like the first person you'd turn to in a problem. "
isProperName = true
isHer = true
;
+bob: Person 'Bob' 'Bob'
"He looks like a Robert, only shorter. "
isProperName = true
isHim = true
;
versionInfo: GameID
name = 'sample'
byline = 'nobody'
authorEmail = 'nobody <foo@bar.com>'
desc = '[This space intentionally left blank]'
version = '1.0'
IFID = '12345'
;
gameMain: GameMainDef
initialPlayerChar = me
;
That gets us:
Void
This is a featureless void.
Alice and Bob are standing here.
>twiddle
You twiddle your thumbs.
>alice, twiddle
Alice twiddles her thumbs.
>bob, twiddle
Bob refuses to twiddle his thumbs.
This is not a particularly good way to implement this particular test case (it would probably make more sense to change the behavior of obeyCommand()
) but what I’m really concerned about here is the mechanics of Action.verifyAction()
in general.