I’ll lead with some demo code:
#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>
modify playerActionMessages
fidgetFoo(fidgeter, other) {
gMessageParams(fidgeter, other);
return('{You/he fidgeter} wait{s fidgeter} for {you/he other}
to do something.' );
}
fidgetBar(fidgeter, other) {
gMessageParams(fidgeter, other);
return('{You/he fidgeter} stare{s fidgeter} silently at
{you/he other}. ' );
}
;
startRoom: Room 'Void' "This is a featureless void. ";
+me: Person;
+alice: Person 'Alice' 'Alice'
"She looks like the first person you'd turn to in a problem. "
isProperName = true
isHer = true
;
++aliceAgenda: AgendaItem
initiallyActive = true
isReady = true
invokeItem() {
switch(rand(3)) {
case 1:
fidget(&fidgetFoo, me);
break;
case 2:
fidget(&fidgetBar, me);
break;
default:
fidget('Alice does nothing in particular. ');
break;
}
}
fidget(msg, fidgetAt?) {
local obj;
obj = new MessageResult(msg, getActor, fidgetAt);
defaultReport(obj.messageText_);
}
;
versionInfo: GameID;
gameMain: GameMainDef initialPlayerChar = me;
This defines a couple new messages (as methods with arguments) on playerActionMessages
. If you call them via defaultReport()
or a related reporting macro, you could do something like:
defaultReport(&fidgetFoo, alice, me);
This works because the reporting macros create a new report and add it to the transcript, and under the hood the report classes have constructors that evaluate the message/arguments by creating a MessageResult
, and its constructor checks to see if the first arg to the constructor is a property, and if it is it checks playerActionMessages
and does the right thing.
In the demo code as written I could absolutely just call defaultReport()
(which is what eventually happens anyway), but in cases where I need the evaluated string value, what are the options?
Here I just create a MessageResult
instance and then use the instance’s messageText_
, which will contain the evaluated string. You could also just call playerActionMessages.fidgetFoo()
and so on directly, but that’s substantially more awkward that just being able to use &fidgetFoo
(or whatever) as an argument.
So…is there some more convenient way of doing this?