changing name of Actor not working (adv3Lite)

I have an NPC known simply as agent until he is engaged in conversation, where he reveals his name to be Bo.

I want to reflect that new knowledge in the Actor object’s vocab property so that a command like give Bo the letter will work once his name is known.

I have a setName(str) method in the Actor object…

    setName(str)
    {
        local oldName = name;
        name = str;
        proper = true;
        otherGuy.addVocabWord(oldName, MatchNoun);
    }

This code is modeled after an example cribbed from the Adv3Lite tutorial, where the flight attendant becomes Angela during a conversation.

When I call the setName() method, the Actor name property changes as expected, but the command give bo the letter fails because there is no bo.

I don’t understand why my example is not working when it appears to work in the tutorial. What am I missing?

Here’s the test bed code…

[code]
#charset “us-ascii”

#include <tads.h>
#include “advlite.h”

versionInfo: GameID
IFID = ‘445C38A3-AD1B-4729-957A-F584600DE5C1’
name = ‘test’
byline = ‘by Jerry Ford’
htmlByline = ‘by
Jerry Ford

version = ‘1’
authorEmail = ‘Jerry Ford jerry.o.ford@gmail.com
desc = ‘Testing Actor name change.’
htmlDesc = ‘Testing Actor name change.’

;

gameMain: GameMainDef
initialPlayerChar = me
paraBrksBtwnSubcontents = nil

;

me: Actor ‘me’ @room
“The main man.<.p>”
isHim = true

person = 2

;

  • letter: Thing ‘letter’
    “The letter for Bo.<.p>”
    ;

room: Room ‘room’
“The room. <.p>”

;

otherGuy: Actor ‘agent;;man person;him’ @room
desc = “The agent stands in the middle of the room. <.p>”

setName(str)
{
    local oldName = name;
    name = str;
    proper = true;
    otherGuy.addVocabWord(oldName, MatchNoun);
}

;

  • HelloTopic
    “Hello, you say. What’s your name? \b
    Bo. The name’s Bo, the other guy replies. <.p>
    <<otherGuy.setName(‘Bo’)>>”
    ;
  • GiveTopic @letter
    “Oh, Bo, huh? I have a letter for you, you say. <.p>”
    ;
    [/code]

Jerry

I haven’t tried it out, but it looks to me like the problem is that you’re adding the old name to the vocabulary instead of the new one:

 setName(str)
    {
        local oldName = name;
        name = str;
        proper = true;
        otherGuy.addVocabWord(oldName, MatchNoun); // Here you're just adding oldName to the vocabulary, when it's already there.
    }

What you need to do is to add the new name:

 setName(str)
    {        
        name = str;
        proper = true;
        otherGuy.addVocabWord(str, MatchNoun); // Add the new name, that wasn't there before.
    }

Note that in the Angela example in the tutoral, ‘angela’ is already in the vocab from the start, so this isn’t an issue:

angela: Actor 'flight attendant; statuesque young; woman angela; her'
    @planeFront
    "She's a statuesque and by no means unattractive young woman. "
    
    checkAttackMsg = 'That would be cruel and unnecessary. '
    
    globalParamName = 'angela'
    
    makeProper
    {
        proper = true;
        name = 'Angela';
        return name;
    }
;

Ah ha! That’s what I was missing! I thought setting name to some value for str would add str’s value to the vocab automatically. I seen now that is not what happens.

But that also means that the first value of the vocab string is not the name property. Yet, if I enter eval otherGuy.name before the name change, the code returns agent—the first value of vocab. Then, after the change, eval otherGuy.name returns Bo, even though I have not yet changed the vocab string.

Note that I’m not complaining about how this works. It’s okay with me, I’m just noting that it was a source of confusion for me.

(Well, hmmm, a brief excursion into the docs and I now discover this in the Adv3Lite Manual: Explicity defining the name (short name) property will override any name the library would otherwise have inferred from the vocab property. I guess I just cored another RTFM.)

Yes, that was intentional, I didn’t want the new name “Bo” to replace the old name “agent” in the vocab string, I want both “Bo” and “agent” to work after the name is revealed.

But I see now it isn’t necessary for me to include this preservation code, just need to add the new value into the vocab string, and the old value stays in place.

Live and learn. :slight_smile:

Thanks.

Jerry