Mr Socks is a pink and green knitted cat...


#1

So, I wanted to be able to write Mr Socks is a pink and green knitted cat.

Looking at various examples, colour usually seems to be modelled as a property. That seems to work well enough for things with a single colour. However Mr Socks is stripy, so this won’t work…

Modelling the colours as a list does work, but I couldn’t make it read well:

Mr Socks is a knitted cat. The colour is {pink, green}.

Yuck! Also it’s tedious for those objects which are non-stripey (how gauche!) and have to be described with a single-valued list.
Worse, I couldn’t find a simple way to “understand” the colours. e.g. refer to “pink” or “the green cat” automatically. Understand’ing a property seems to work only for single values, not a list of them.

For now, I’ve come up with this, which is verbose, but seems to do what I want:

[code]A hue is a kind of thing. [not a value, because we want a printed name]

A thing can be pink.
Pinkness is a hue. The printed name is “pink”.
Understand the pink property as describing a thing.

A thing can be green.
Greenness is a hue. The printed name is “green”.
Understand the green property as describing a thing.

To decide what list of hues is the colour of (T - a thing):
Let L be a list of hues;
if T is pink, add pinkness to L;
if T is green, add greenness to L;
decide on L.

A cat is a kind of animal.
A cat can be knitted.

Mr Socks is a pink and green knitted cat.
He is in a room called the Kitchen.
When play begins: say “Mr Socks is [the colour of Mr Socks].”[/code]

Is that a reasonable approach? I’d like to define these colours in a table, but it doesn’t seem to be possible to put a property in a table.
I’m assuming it’s possible to make that more compact (certainly by dropping into Inform6 as a last resort), but that’s a secondary concern.


(Andrew Plotkin) #2

Is the intent just to make your source code read better? This is not only verbose, it’s inefficient to parse.

Are you going to have several multicolored objects?


#3

Thanks, let me try to clarify:

  1. The requirement does arise from the character:
    Mr Socks is stripy, and therefore likes stripy things and dislikes monochrome things.
    I can think of a few nice descriptions and potentially some puzzles based on that.

  2. But this is also effectively structured play: I’m only just learning Inform 7, so I’m excited to
    learn more about what works better, both for the source code and for the engine itself.

So yes, the current implementation is largely an idle curiosity (and yes, part of me just wanted
to be able to write that sentence), but it does arise from a problem that I’ve played with several ways,
none of which seem entirely satisfactory.


(Hanon Ondricek) #4

Have you checked out the Recipe Book 9:7 “Painting and Labeling Devices” - It’s about changing properties of things but may give some example code along the lines of what you are doing.
inform7.com/learn/man/RB_9_7.html


#5

Oh, thanks! One of those examples suggests a label which is part of a thing. That suggests modelling the stripe in the same way, so…

[code]Colour is a kind of value. The colours are uncoloured, pink and green.
A stripe is a kind of thing. A stripe is part of every animal.
Every thing has a colour.

Mr Socks is a pink animal. The stripe is green.[/code]

It’s not quite as nicely phrased, and it does mean that every animal is modelled as having a stripe… that’s fine, as we can ignore it if the stripe is in fact uncoloured. Not sure if this has legs, but definitely worth a play :wink:


#6

And… with a bit more thought and play, I think this is better:

[code]Colour is a kind of value. The colours are pink and green.
Colouring relates one animal to various colours.
The verb to be coloured means the colouring relation.
The verb to be resplendent in means the colouring relation.

Mr Socks is an animal. He is resplendent in pink and green.[/code]

Hurrah!

osf’


(matt w) #7

If you turn the colours from a kind of value to a kind of thing, you can even have them be understood:

[code] Lab is a room.

Colour is a kind of thing. Pink and green are colours.
Colouring relates one animal to various colours.
The verb to be coloured means the colouring relation.
The verb to be resplendent in means the colouring relation.

Mr Socks is an animal in Lab. He is resplendent in pink and green.

Understand "[something related by colouring]" as an animal.[/code]

They have to be a kind of thing because, as the compiler informed me the first time I tried it, understanding by relations doesn’t work with kinds of value. But this creates them offstage where they can’t do any harm.

Unfortunately this won’t allow “x pink and green cat” (assuming that you are understanding “cat” as a cat), because the parser wants to understand that as applying to two things: “x (pink) and (green cat).” It will tell you you can’t do that to multiple objects. This might be something that can be worked around with some sort of thing that replaces the word “and” in such constructions. Or it might not. I tried a bit with regular expressions and realized that I now had two problems. So it might not be worth it (I also understand that understanding by relations can be computationally slow).