Testing for an attribute and printing a message if it passes

I'm trying to get this to work in the room description
If Mary has a Corolla car then I want the message "She has a great car" printed

I tried this code which did not work:
{if Mary.car="Corolla":She has a great car}


I have since found that this works:
{if Mary.car=Corolla:She has a great car}


Yeah, the text processor if is really weird.

The left hand side of the expression is either object.attribute or the name of an attribute of the game element. If this attribute is an object, it's replaced by its name.
For <, >, <=, or >=, both the left hand side and right hand side are converted to doubles and then compared. For = and <>, both sides are treated as strings. If none of these operators are found, the expression is treated as a boolean attribute (possibly preceded by the word not) .

Also beware of using this. An expression like {if player.catchphrase=this is Sparta!:some response} will most likely fail - because the text processor does a search-and-replace, changing this to the name of the current object (or whatever object is in the attribute game.text_processor_this) before it compares the values.

I usually prefer to use either, because it at least follows the same rules as the rest of Quest.
This will work fine:

{either Mary.car="Corolla":She has a great car}

(within {either, you can use "this" to refer to the object stored in game.text_processor_this, but unlike {if it only behaves like that if this is being used as the name of an object; not if it appears in an attribute name or in a string)


Hi mrangel.

the command "either" is a strange one as it suggests that both conditions can be correct (like a OR statement). Good to know that it can be used in Quest thanks.

I'm getting into the habit of reducing object names to one or two words and having the descriptive name as a prefix.
So I'm thinking that if "this is Spartal" is used in the prefix then there should be no problem with using "this" word "this"


I'm getting into the habit of reducing object names to one or two words and having the descriptive name as a prefix.

Generally, you want to put an object's descriptive name in its alias.
The alias is the name the player sees, the name is only used in your code.


Log in to post a reply.

Support

Forums