How to print an Object's Alias in a message

How would I write the following printed message as an expression?

eat [Object Alias]
"You have eaten the " [Object Alias] "{Random message from list "X"}"

where list "X" would be:

  • High quality food
  • low quality food
  • raw / rotten food"

For the sake of things like {It was delicious!:It is very filling!} vs {It's not so tasty...: but it makes you feel a little unwell...}

Although tbh I may just have attributes for 'Good/poor/raw' and handle the list inside the 'eat' Command with
If HasAttribute [quality_stipulation]
then
msg {random:etc:}

following that with the code for reading health and satiation gains completely independant of the 'If [quality] then [message category]'

I mainly want to know how to express [Object.Alias] inside a print message expression.


You can either use the + operator to join two strings together:

msg ("You eat " + GetDefiniteName(object) + ".")

The functions available are:

  • GetDisplayAlias (object) - gets the object's alias if it has one, or its name otherwise
  • GetDisplayName (object) - gets the object's alias and article (usually adding "a" or "an")
  • GetDefiniteName (object) - gets the object's alias and adds the definite article ("the") unless the object is a named NPC

A common way to do stuff like this is to use the text processor; but the text processor doesn't have access to variables outside it. So you would need to use a little kludge to make it work:

game.text_processor_this = object
msg ("You eat the {this.alias}.")

You can put {objectname.attribute} in any text you print, and it will display the value. But the only variables it allows are this (which is whatever object game.text_processor_this is set to) or any keys in the dictionary game.text_processor_variables.

Or you could use the {object: text processor command:

game.text_processor_this = object
msg ("You eat the {object:this}.")

(Probably doesn't make a difference in the case of an object you're eating; but for an object that still exists at the end of the turn, this method creates a link that the player can click on)

If there are multiple variables in the command (such as a throw #object1# at #object2# command), one useful trick it:

game.text_processor_variables = game.pov.currentcommandresolvedelements
msg ("You lob the {object:object1}, but it just bounces off the {object:object2}. {object2.gender} isn't affected.")

(game.text_processor_variables is a dictionary of variables which are accessible to the text processor; and game.pov.currentcommandresolvedelements is a dictionary of variables passed to the current command, so this is a quick way to pass all of them across)


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

Support

Forums