Changing npc alias

Hello everyone,
So here's the context with an example.

My player has a switchable object:
Black Watch (default = OFF)

I have a npc object who has the attributes:
name = "npc1"
if(Black Watch is switched off)
{
alias = "totally normal salary man"
}
else
{
alias = "Rogue (Serial Killer)"
}

Now my problem is no matter how much I switch ON or OFF with the is switched off condition. I always see the object in the room description like this:

description = "blablabla npc1 blablabla"

instead of:

description = "blablabla totally normal salary man blablabla"
or
description = "blablabla Rogue (Serial Killer) blablabla"

It is because I've misunderstood the usage of an alias? Or do I have to change the entire name that doesn't like this: "name (character title between those)" ?


Is it npc1.alias?


You'll have to do npc1.alias = "whatever you want" or this.alias = "whatever you want".

For the description you'll have to use concatenation and do "blah blah blah " + this.alias + " blah blah blah". Make sure you change the description into a script.


It is npc1.alias for the attribute.
I wanted to use that method to rename the npc within a same room.

So I didn't need to duplicate him from hidden to revealed.

That way the room description will change alias 1 into alias 2 depending on the state if the watch.

I want that alias to change the displayed object name in the room description.


Its difficult to tell without seeing your Quest project so you'll have to keep double checking things until you find the issue. If you have the following then it should be working.

Your if statement should be similar to this.


if (Black Watch is switched off){
     npc1.alias = "totally normal salary man"
}
else {
     npc1.alias = "Rogue (Serial Killer)"
}

Your description should look something like this.


npc1.description = "Your text here " + npc1.alias + " your text here."

Lastly, make sure that the watch is actually being switched on and off.


Your description should look something like this.

If the room description is text rather than a script, it would make more sense to have something like:

blah blah blah {object:npc1} blah blah blah

There is no real need to use a script unless you're doing something that only a script can do.


-GamerOver9000
I see. I will try it right away! Thank you for the example.

-mrangel
So it's actually better to disable the auto description and make our own room description? Does it affect the north, south, east, west, etc directions?

Or did I misunderstand something?


I can confirm that I can switch the watch on and off work (because I've used two different descriptions for Rogue).
But my npc keep being called "npc1".

It is normal, when you leave the code view and look at the object setup of npc1 to see the alias empty by default? I can't write anything inside (it doesn't let me) so I guess it detects the script but can't set a new alias on an empty string?

I'm really confused x)


So it's actually better to disable the auto description and make our own room description? Does it affect the north, south, east, west, etc directions?

No, I was responding to the previous suggestion to use scripts.

So… does switching the watch on and off change both the NPC's look and alias attributes?

It would be helpful if you could show the script you are using for this, and where you are using it.

Are you switching it on or off before entering the room?


Okay, so here is the basic script for the salary man (Rogue):

      <inherit name="editor_object" />
      <inherit name="male" />
      <drop type="boolean">false</drop>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
      <usedefaultprefix type="boolean">false</usedefaultprefix>
      <alt type="stringlist" />
      <inventoryverbs type="stringlist">
        <value>Look at</value>
      </inventoryverbs>
      <scenery type="boolean">false</scenery>
      <attr name="feature_startscript" type="boolean">false</attr>
      <attr name="feature_player" type="boolean">false</attr>
      <suffix type="string"></suffix>
      <not_all />
      <look type="script">
        if (not IsSwitchedOn(Black Watch)) {
          msg ("Here is Rogue the murderer!")
        }
        else {
          msg ("A normal salary man")
        }
      </look>
      <alias type="script">
        if (IsSwitchedOn(Black Watch)) {
          npc1.alias = "Rogue (Serial Killer)"
          return (alias)
        }
        else {
          npc1.alias = "Salary man"
          return (alias)
        }
      </alias>
    </object>

It actually works for the [look] command, but not for the {alias} attribute. I always see the default description with "npc1" showing up and not the alias for some reasons...


Ah… that's the issue. When displaying the list of objects in a room, Quest uses GetDisplayAlias, which does the following:

  • If the object has a string attribute called alias
    • Return the alias
  • else
    • Return the name

In this case, the alias is a script, but there's nothing that runs a script.

You could set the alias to be the string: {either IsSwitchedOn(Black Watch):Rogue (Serial Killer):Salary Man} - that will work in room descriptions, because Text Processor directives like {either are automatically run when the string is printed. But that won't work for the Places and Objects pane in the sidebar, which will display the code instead of the name.

Alternatively, you could run the code when the watch is switched on or off; which is what it sounded like you were doing from your original post.

On the "Black Watch" object's "switchable" tab, you could use the two scripts at the bottom.

  • "After switching on the object:"
     npc1.alias = "Rogue (Serial Killer)"
  • "After switching off the object:"
     npc1.alias = "Salary man"

The downside of this method is that your Black Watch ends up containing a big list of characters' alternate names.

If there are a lot of characters this applies to, then it might be worth making a more general script:

  • "After switching on the object:"
 foreach (obj, AllObjects ()) {
  if (HasAttribute (obj, "watch_on_alias")) {
    obj.watch_off_alias = obj.alias
    obj.alias = obj.watch_on_alias
  }
}
  • "After switching off the object:"
 foreach (obj, AllObjects ()) {
  if (HasAttribute (obj, "watch_off_alias")) {
    obj.watch_on_alias = obj.alias
    obj.alias = obj.watch_off_alias
  }
}

Then you could give the man two attributes:

      <alias type="string">Salary man</alias>
      <attr name="watch_on_alias" type="string">Rogue (Serial Killer)</attr>

and it will switch between them as necessary (assuming the watch is initially switched off)

The advantage of this method is that each object's real alias is stored on that object, rather than in a single big list; and the script doesn't need modifying as more NPCs are added to the system.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums