Conditional text with properties not working as I expected

Hi folks,

I’m working on some code, and I’ve run into something I don’t understand. I’m trying to have generic hats that change their descriptions depending on the type of hat. What I’ve found is that the type seems to be the default in conditions (in the text) but correct when explicitly said (in the same text).

That’s probably unclear, so here’s a minimal example that demonstrates it:

"The mad hatter"

Laboratory is a room.

A headware is a kind of thing.

A hat-style is a kind of value. The hat-styles are baseball cap, stockman's hat.

Understand "baseball/cap" as baseball cap.
Understand "stockman's/hat" as stockman's hat.

A headware has a hat-style. Understand the hat-style property as describing a headware. The printed name of a headware is "[hat-style]".
The description is "[if hat-style is baseball cap]A simple baseball cap.[otherwise if hat-style is stockman's hat]A traditional stockman's hat.[end if] The style is [hat-style].".

A souvenir is a headware in the laboratory. The hat-style of the souvenir is baseball cap.
An Akubra is a headware in the laboratory. The hat-style of Akubra is stockman's hat.

When I run it, I get:

Laboratory

You can see a baseball cap and a stockman's hat here.

>x akubra

A simple baseball cap. The style is stockman's hat.

>x souvenir

A simple baseball cap. The style is baseball cap.

I’d appreciate any help!

Your unexpected result comes from trying to check if hat-style is baseball cap, which evaluates to true (i.e. that’s one of the values). The condition is satisfied and Inform doesn’t go on to your otherwise if… clause. A little specificity clears this up for Inform:

The description is "[if hat-style of the item described is baseball cap]A simple baseball cap.[otherwise if hat-style is stockman's hat]A traditional stockman's hat.[end if] The style is [hat-style].".

the item described here matches the thing with the description being printed, so now we’re checking the hat-style of something, rather than the values of hat-style.

EDIT: Grammar.

1 Like

Thank you! I was quite confused by the fact that the correct value was output in [hat-style]. I know I’ve read this paragraph in the documentation several times before and never understood why it was important. “useful” indeed :slight_smile:

When varying descriptions are being given for kinds of rooms or things, it can be useful to make use of a special value called “item described”, which refers to the particular one being looked at right now

1 Like

That is confusing! It’s really not consistent, and you could reasonably call this a bug.

My usual rubric is that you can use a bare style name (like hat-style) in a description property, because Inform knows what item the description applies to. But I guess that’s not true at present. You can print hat-style but not use it otherwise (without applying ...of the item described, which always works).

1 Like

Yeah, I would call this a bug. If the property has its own name, rather than being named after the kind of value, it works. If that’s not valid with “anonymous” properties (ones just named after their type), the compiler should complain about it.

1 Like

Hm, does it?

A headware is a kind of thing.

A hat-style-kind is a kind of value. The hat-style-kinds are baseball cap, stockman's hat.

Understand "baseball/cap" as baseball cap.
Understand "stockman's/hat" as stockman's hat.

A headware has a hat-style-kind called the hat-style.
Understand the hat-style property as describing a headware.
The printed name of a headware is "[hat-style]".
The description is "[if hat-style is baseball cap]A simple baseball cap.[otherwise if hat-style is stockman's hat]A traditional stockman's hat.[end if] The style is [hat-style].".

A souvenir is a headware in the laboratory. The hat-style of the souvenir is baseball cap.
An Akubra is a headware in the laboratory. The hat-style of Akubra is stockman's hat.

This still doesn’t work, although with the opposite problem: the tests are always false.

>x akubra
 The style is stockman's hat.
1 Like

Reported as I7-2347.

2 Likes

Aha, you’re right. I was thinking of adjectives rather than properties:

A headwear can be caplike or hatlike.
A headwear is usually caplike.
The printed name of a headwear is usually "[if caplike]Caplike[else]Hatlike[end if] headwear".

Oh yes, I tried a named property and it was exactly the same. I forgot to say.

I also tried all the Inform versions that Borogrove (and I) have and they all did the same thing, too.

Yay! I’m finding bugs! Usually it’s my mistake, so it’s nice that this time I wasn’t completely confused.

2 Likes