Grouping by a property

I am trying to work out how to group a certain category of objects together according to a property. Hopefully the simplest way to explain what I want is using an example:

"Blobs"

Laboratory is a room.

Blob-colour is a kind of value. The blob-colours are red, green and blue.

A blob is a kind of thing. A blob has a blob-colour called the colour. Understand the colour property as describing a blob.

Before listing contents:
	Group red blobs together as "red blobs".

A blob called a big red blob is here. The colour is red.
A blob called the small red blob is here. The colour is red.
A screw is here.
A blob called the big green blob is here. The colour is green.
A blob called the huge blue blob is here. The colour is blue.
A widget is here.
A blob called the tiny green blob is here. The colour is green.

If I replace the listing contents rule with Group blobs together as "blobs" it will happily collect all five blobs together in the room contents listing. But I can’t figure out how to qualify the description of which things I want to group to restrict it to a single colour because Inform doesn’t seem to understand that the word “red” in “group red blobs together” refers to the blob-colour property (despite the “understand the blob-colour property as describing a blob” line).

How do I turn the blob-colour property into something that Inform understands as a description?

You can create a property via a definition:

"Blobs"

Laboratory is a room.

Blob-colour is a kind of value. The blob-colours are red, green and blue.

A blob is a kind of thing. A blob has a blob-colour called the colour. Understand the colour property as describing a blob.

Definition: A blob is red-colored if the colour of it is red.

Before listing contents:
	Group red-colored blobs together as "red blobs".

A blob called a big red blob is here. The colour is red.
A blob called the small red blob is here. The colour is red.
A screw is here.
A blob called the big green blob is here. The colour is green.
A blob called the huge blue blob is here. The colour is blue.
A widget is here.
A blob called the tiny green blob is here. The colour is green.
2 Likes

Thank you!

A further question: is it possible to say something like “Definition: a blob is C-coloured if the colour of it is C”, or do I have to just write a definition for each colour by hand?

To make it work the way you think it should, you need to use “nameless” properties.

Instead of

A blob has a blob-colour called the colour.

just

A blob has a blob-colour.

That way the phrase red blobs will have the meaning that you expect. You can also simplify your declarations a bit:

A green blob called a big green blob is here.
2 Likes

This looks like it should make everything a million times easier, but either I’ve missed a crucial detail or it doesn’t work. I changed the code to this:

"Blobs"

Laboratory is a room.

Blob-colour is a kind of value. The blob-colours are red, green and blue.

A blob is a kind of thing. A blob has a blob-colour. Understand the blob-colour property as describing a blob.

Before listing contents:
	Group red blobs together as "red blobs".

A red blob called a big red blob is here.
A red blob called a small red blob is here.
A screw is here.
A green blob called a big green blob is here.
A blue blob called a huge blue blob is here.
A widget is here.
A green blob called a tiny green blob is here.

But the compiler protests:

Problem. You wrote ‘A red blob called a small red blob is here’ (line 13): but I can only make ‘a something called whatever’ when the something is a kind I know, possibly qualified with adjectives. For instance, ‘an open door called the Marble Door’ is fine because ‘door’ is the name of a kind and ‘open’ is an adjective which means something for doors. But ‘a grand archway called the Great Gates’ would not normally mean anything to me, because ‘archway’ is not one of the standard kinds in Inform. (Try consulting the Kinds index.)

I think in this case you’d need to activate a use option:

Use unabbreviated object names.

With that on, in 6M62, I can do:

There is a red blob called a big red blob. It is here.
In the Laboratory is a red blob called a small red blob.
A screw is here.
Here is a green blob called a big green blob.
A blue blob called a huge blue blob is in Laboratory.
A widget is here.
A green blob called a tiny green blob is here.
1 Like

With a little more systematic code and with fewer induced shortcuts, it works:

Lab is a room.

A blob is a kind of thing.

Colour is a kind of value.
The colours are blue, red and green.

Size is a kind of value.
The sizes are tiny, small, medium, big and huge.

A blob has a colour.
The colour of a blob is usually red.

A blob has a size.
The size of a blob is usually small.

Rule for printing the name of a blob (called the LocalBlob):
	say "[colour of LocalBlob] [size of LocalBlob] blob";
	
Blob01, blob02, blob03, blob04 and blob05 are blobs in Lab.

The colour of Blob01 is red.
The size of Blob01 is big.

The colour of Blob02 is blue.
The size of Blob02 is big.
	
The colour of Blob03 is green.
The size of Blob03 is tiny.

The colour of Blob04 is red.
The size of Blob04 is medium.

The colour of Blob05 is red.
The size of Blob05 is huge.

Before listing contents:
	Group red blobs together as "red blobs".
Lab
You can see blue big blob, green tiny blob and three red blobs (red big blob, red medium blob and red huge blob) here.


>

EDIT : unuseful spaces removed.

Oh, I hadn’t spotted that it was only the second definition onwards that was causing the problem! Presumably because “a red blob” in the second line is taken as meaning the big red blob that was already defined, rather than a new one?

Now I have to decide whether I can stand to use unabbreviated object names throughout the whole project …