T3: DefaultTellTopic

Here’s a code snippet that doesn’t work in the way I’d like it to:

+ DefaultTellTopic topicResponse = "<.q><<if (joe.canSee(gIobj))>>I'm looking right at it, man<<else>>Not too sure what you're talking about, guy<<end>>,<./q> Joe replies. " ;
The problem, of course, is that the ‘tell joe about X’ command produces a topic match, not a gIobj. (Thus gIobj is always nil when this code is executed.)

It should be obvious what I’m trying to do. If the NPC can see the object that is the topic, I want to print one response, and if he can’t see it, I want a different response. So … how can I get at the resolved topic object in order to create a logical test for whether Joe can see it?

Hah! Solved it.


  • DefaultTellTopic
    topicResponse {
    local obj = gTopic.getBestMatch();
    "<.q><<if (joe.canSee(obj))>>I’m looking right at {it obj/him}, man<>Not
    too sure what you’re talking about, guy<>,<./q> Joe replies. ";
    This might conceivably fail in situations where there are multiple matches of equal likelihood, but I’ll cross that bridge when I come to it.