Dear Eric and other adv3Lite users,
I’m trying to define a new TAction in my game, and I noticed something I don’t quite understand.
My verb, being a TAction, takes a single object. Let’s call the verb “Rub”. Only one object responds to the verb in a complex way, others just display some text. But since I want different objects to respond with different text, it seems a burden to write dobjFor(Rub) for everything, and I want to define a “rubDesc” property similar to the “listenDesc” already implemented in adv3Lite.
And of course, there is still a default text for a large number of objects, so I have the dobjFor(Rub) method of Thing class to test if rubDesc property is defined, and if not, display the default text.
Sample code:
[code]DefineTAction( Rub );
VerbRule( Rub ) ‘rub’ singleDobj : VerbProduction
action = Rub
verbPhrase = ‘rub/rubbing (what)’
missingQ = ‘what do you want to rub’
;
modify Thing
rubDesc = nil
dobjFor( Rub ) {
action() {
if ( rubDesc == nil ) { // This doesn’t work as expected
"It doesn’t achieve anything. ";
} else {
rubDesc;
}
}
}
;[/code]
However, this doesn’t quite work. I looked up in adv3Lite’s source code, and found out that the library uses “propType(&prop) == TypeNil” test. I changed the line in my code to “if ( propType( &rubDesc ) == TypeNil ) {”, and it worked. (The library also uses “display(rubDesc);” but that’s not related.)
My question is, what is special about the propType(&prop) == TypeNil test? The “dobjFor()” is a macro, and the above code should expand to the “actionDobjRub()” method of Thing. Why can’t it use the rubDesc == nil test then? Does this have something to do with how propertyset works?
Thanks in advance,
Ming