Outputting different aliases in printed messages.

So in my game I have an elf, but later you learn his name (I'll say Adam for short). Changing his name as an object is easy by switching his alias (From elf to Adam), but what about text?

For example, how do I make it so the text changes depending on whether you know his name?
For example:
The elf enters the room.
Adam enters the room.

I'm sure is simple and sorry for asking such mundane question but still learning


In a message, you can easily display the alias for an object:

{elfdude.alias} enters the room.

or

{object:elfdude} enters the room.

(the elfdude in those examples is the name that you want to change to an alias)


Hello.

EDIT

I just saw that mrangel posted a solution while I was typing this, and it looks like it should do the trick just fine (plus, it is much more simple than what I'm suggesting). :)

Only try the following if mangel's solution is not quite what you're looking for (but it looks like his solution should work just fine).


I always try to make my games behave this way, too.

The answer can be complicated, or not, depending on what other code might be in your game.

This also depends on which script is printing the text.

Are you using the Followers library? Are you just moving the elf object in a script of your own and just adding that text in said script?

If you are using your own script to print that specific text, and you know it only needs to print "elf" once:

{once:The elf}{notfirst:Adam} enters the room.

That should suffice.

If, though, you have a script which, when triggered, tells the player that the elf's name is Adam, and this script may or may not trigger after the first time the text prints, you could set a boolean attribute on the elfobject to know if the name is known.

Something like this (edited: version 2):

<!--Saved by Quest 5.8.7753.35184-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="elfname">
    <gameid>c03c1a78-33d2-4d9a-a9ba-feda4ccf2922</gameid>
    <version>0.2</version>
    <firstpublished>2021</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="elf">
      <inherit name="editor_object" />
      <inherit name="namedmale" />
      <alias>elf</alias>
      <usedefaultprefix />
      <speak type="script">
        OutputTextNoBr ("\"Hello,\" says {either elf.alias=\"elf\":the elf:Adam}.")
        if (not this.alias = "Adam") {
          msg (" \"My name is Adam!\".")
          this.alias = "Adam"
          this.usedefaultprefix = false
        }
        else {
          msg ("")
        }
      </speak>
      <look>{either elf.alias="elf":The elf:Adam} is just an ordinary elf.</look>
      <attr name="name_known" type="boolean">false</attr>
    </object>
  </object>
</asl>

If you are using a library that is printing that text, I would add the function to my game's main code and modify it. (If you need help with that, just let us know which library it is.)


Log in to post a reply.

Support

Forums