Say I have some objects that I want to always be in scope. Then all I need to do is twiddle the objects (and/or their parent class(es)) to add themselves to scope via getExtraScopeItems()
(alternately, the objects can be added by whatever Actor
class needs to have the objects in scope for their actions). That’s straightforward.
Now let’s say I want to include/exclude the object(s) for specific group(s) of actions. How does one do this?
We can’t just check gAction
(either for identity or for class membership) because although gAction
is defined when getExtraScopeItems()
is called, it apparently isn’t configured yet (that is, if the command is >EXAMINE PEBBLE
then gAction
will be an instance of Action
but it will not yet be an instance of ExamineAction
).
This is (reasonably) straightforward if only one Action
or Thing
needs to be tweaked, because then it could be hashed out in a dobjFor()
on the object for the specific action, or something like that. But I want something like “pebbles are always in scope, except when the action is one of [ some list ]”.
For some cases, this “just works” because of additional checks on the action (for example, checking for reachability in TakeAction
). But in other cases it doesn’t, and having extra objects in scope produces unexpected behaviors (if the additional object is a Person
, then things like >ASK ABOUT PEBBLE
will force a disambiguation even if one person is present).
Simple illustration of the issue. Here we define a _foozle
property on Action
which defaults to nil
but is explicitly set to a unique numeric value for ExamineAction
and TakeAction
:
#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>
modify Person
getExtraScopeItems(actor) {
local lst;
lst = inherited(actor);
if((actor != self) || !gAction)
return(lst);
if(gAction.ofKind(ExamineAction)) "ExamineAction\n ";
if(gAction.ofKind(TakeAction)) "TakeAction\n ";
"gAction._foozle = <<gAction._foozle ? toString(gAction._foozle)
: 'nil'>>\n ";
return(lst);
}
;
modify Action _foozle = nil;
modify ExamineAction _foozle = 1;
modify TakeAction _foozle = 2;
startRoom: Room 'Void'
"This is a featureless void. "
;
+me: Person;
+pebble: Thing 'small round pebble' 'pebble'
"A small, round pebble. "
dobjFor(Examine) {
action() {
inherited();
if(gAction.ofKind(ExamineAction)) "action: ExamineAction\n ";
if(gAction.ofKind(TakeAction)) "action: TakeAction\n ";
"action: gAction._foozle = <<gAction._foozle ? toString(gAction._foozle) : 'nil'>>\n ";
}
}
;
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
;
Sample transcript:
Void
This is a featureless void.
You see a pebble here.
>x pebble
gAction._foozle = nil
A small, round pebble. action: ExamineAction
action: gAction._foozle = 1
The output for >X PEBBLE
just demonstrates that gAction
isn’t “complete” when getExtraScopeItems()
is called, but it is by the time pebble.dobjFor(Examine)
is called.