Kind of a noob, need help.

In my game i’m having some trouble with kinds, properties, and values. Currently I get the problem “You wrote ‘The top-type of top is t-shirt’ but the property top-type for the top is not allowed to exist, because you haven’t said it is. What properties something can have depends on what kind of thing it is: see the index for details.”

The code looks like this.

[code]A top-type is a kind of value. The top-types are sweater, hoodie, t-shirt and coat. is a kind of value. A has top-type.

There is a top in the closet. A top has The top-type of top is t-shirt.[/code]

Please help me I’m so confused.


Here’s one way to implement the clothing in your example:

Section 1 - Clothing

Clothing is a kind of wearable thing.

A top is a kind of clothing.

A sweater is a kind of top.
A hoodie is a kind of top.
A t-shirt is a kind of top. Understand "t" or "shirt" or "tee" as a t-shirt.
A coat is a kind of top.

Section 2 - Bedroom

Bedroom is a room. "This is your bedroom. Its most notable feature is the closet."

The closet is a scenery container in the Bedroom.

There is a t-shirt in the closet.

Section 3 - Tests

Test me with "x closet / take shirt / wear shirt".

Here, we’ve defined the various kinds of clothing as a hierarchy of Inform 7 kinds. Clothing is a kind of thing, top is a kind of clothing, and sweater/hoodie/t-shirt/coat are all kinds of tops. Kinds are used when we want to create a taxonomy of objects and treat them differently based on what they are. We can write rules applying to all things, to clothing, only to tops, or just to sweaters.

Properties are attributes that we associate with objects – usually all objects of a certain kind. They can be boolean (either-or) properties or value properties (a number, some text, etc.). The default kinds in Inform (like thing) all have a bunch of properties predefined, and we can define more. Here’s an example of attaching a number property to the clothing kind. Add this to the program above and try putting on and taking off the shirt a few times.

Clothing has a number called times worn.

After wearing clothing:
	now the times worn of the noun is the times worn of the noun + 1;
	say "You put on [the noun]. You've now worn it [times worn of the noun] time[s]."

Kinds of value are used to define properties that have a limited number of discrete values that they can assume. This could be implemented manually by using numerical values and assigning a meaning to them, but I7’s kinds of value will do this for us, allowing us to print out the textual meanings of the values easily and making our source code more readable. Here’s an example. Add this to the program, then try putting on the sweater and waiting for several turns.

Itchiness is a kind of value.
The itchinesses are very comfortable, comfortable, slightly itchy, itchy, very itchy, and intolerably itchy.

A sweater has an itchiness. A sweater is usually very comfortable.

Definition: a sweater is uncomfortable if its itchiness > comfortable.

After taking off a sweater:
	now the noun is very comfortable;
	continue the action.

Every turn when the player is wearing a sweater (called S):
	if S is intolerably itchy:
		say "You grasp at [the S] compulsively...";
		instead try taking off S;
	now S is the itchiness after the itchiness of S;
	if S is uncomfortable, say "[The S] feels [the itchiness of S]."

There is a sweater in the closet.

Note that this example uses some abbreviated syntax that conflates a kind of value with the property that contains it. We say “A sweater is usually very comfortable” instead of the longer “The itchiness of a sweater is usually very comfortable”. See §4.9.

So you should definitely check out Vince’s example, but if you want to know specifically what went wrong with your code, I think it’s a bit of a mix-up between kinds of things and kinds of values. In your code as written, “” isn’t doing anything. You’ve established as a kind of value but haven’t defined any values for it (even if you delete everything about the specific top, Inform will complain about that). If you just wanted to give the specific top a top-type, you could do this, assigning a value of the right kind directly to the top:

[code]Closet is a room. [added this to make it compile]

A top-type is a kind of value. The top-types are sweater, hoodie, t-shirt and coat.
There is a top in the closet. The top has a top-type. The top-type of top is t-shirt.[/code]

where we define the kind of value, give it to our object as a potential property it with “The top has a top-type,” and set it with “The top-type of top is…”

Or this is another approach:

[code]Closet is a room.

A top-type is a kind of value. The top-types are sweater, hoodie, t-shirt and coat. is a kind of thing. A has top-type.

Top is in the closet. The top-type of top is t-shirt.[/code]

Note that is a kind of thing now, which is very different from a kind of value–when you create a kind of thing you don’t have to enumerate them right away, the way you do with a new kind of value. When you create a kind of thing like this, you can assign properties to the kind as we did with “A has top-type”–then everything you define as “A” will wind up with a top-type-valued property. Since we create the top as, we can then set its top-type.

If you had a kind of value that in turn had a value-based property, it’d be something like this:

[code]Closet is a room.

Color is a kind of value. The colors are red, orange, yellow, blue, green, and purple.
Warmth is a kind of value. The warmths are hot, cool, and warm.
A color has a warmth. The warmth of red is hot. The warmth of orange is hot. The warmth of yellow is warm. The warmth of green is warm. The warmth of blue is cool. The warmth of purple is cool.

The top is in closet. The top has a color. The color of top is red. The top is wearable.

Instead of wearing something when the warmth of the color of the noun is hot: say “A bit loud with your outfit, isn’t it?”[/code]

Here, we have two new kinds of value, color and warmth. When we say “A color has a warmth,” that assigns the warmth to the color itself. So when we check for warmth, we have to check “the warmth of the color of the noun”–if we test “the warmth of the noun” instead then Inform will complain when we try to do this with the top, since the top itself doesn’t have a warmth. (Since Inform doesn’t know that we’re trying to check the warmth of the top until we wear it, it will allow the game to compile but will throw a run-time error when we type “wear top.” Actually, the code I wrote is very unsafe because it would be quite possible for the player to try to wear something that has no color–but never mind that for now.)

And don’t feel bad about missing this–it’s very easy to miss! When I was typing up the last example I left out “The top has a color” and got the error about “You haven’t said the top can have the color,” even though I’m reasonably experienced and that was exactly what I was trying to explain! A lot of Inform programming, I’ve found, is about learning how to correct errors rather than avoiding them all.