Accessing a list of a single property of multiple things

Is there a way to build a list of a single property of multiple things of the same kind in Inform 7, for example if you had three animals in a room, each with a property color, is there a way to check if in that list of animals’ colors, at least one of them is blue and one of them is red, for example?

Do you mean that each animal has a property which is a list of colors, as in they might have more than one color?

No, each animal has one single color. I’m trying to find if, for example, there is at least one red animal and one blue animal. This is the first step in doing some color mixing stuff (because these animals glow and the idea is that the light on the walls will be the mixture of the colors of the animals). First step though is to be able to access the colors programmatically.

In python I might do something like:
animal_colors = [x.color for x in list_of_animals]

The direct way:

	if a red animal is in the location and a green animal is in the location: ...

This isn’t creating or checking a list, but it does what you asked.


Phrases like the following are valid:

Instead of waiting:
	if there are at least two grey animals in the location:
		if there is one black animal in the location:
			say "[the list of orange animals in the location].".
1 Like

(After a bit of fiddling:)

It is possible to create a list of colors of animals in a location, but it takes some awkward wording.

The verb to becolor means the color property.
Definition: a color is local-animal-ish if an animal in the location becolors it.

When play begins:
	let L be the list of local-animal-ish colors;
	say "L is [L].";

(Note that this checks animals in the location, that is to say the player’s location. Doing this for an arbitrary location is even more awkward.)

In most cases it’s better to use the examples above, rather than creating this list of colors. But you can do it. Your color-mixing example might be a reason to do it.


Oh that’s way less convoluted than what I was thinking I had to do, thank you. I also didn’t realize that non-boolean properties could just be used as adjectives like that. So I’m guessing you can’t have multiple properties have the same value?

Follow-up question: what would be (other than using a bunch of if statements) a way to implement a more general color mixing system? I was trying to figure out if there was a way to create a more abstracted system for mixing colors (a very simple additive color system that works on two colors).

I am so confused. I have only ever seen “The verb to v means the r relation” construction. I’ve never seen it applied to a property before.

No, you can use the same kind of value for more than one property, but you’d have to name that property and you wouldn’t be able to use it as an adjective like above.

An animal has a color. [<- this creates a property with the same name, "color," as it's kind of value]
An animal has a color called favorite color. [<- this creates a second property using the same KOV]
The description of an animal is usually "[The noun] has fur of [color], but prefers [favorite color].".

Tom is a grey animal in the Lab. [creates an animal with grey as its color property] 
The favorite color of Tom is brown.

That’s chapter 13.9. Verbs for properties is chapter 15.12.

1 Like

Or if you don’t need a one-liner:

let L be a list of colors;
repeat with the creature running through animals in the location:
    add the color of the creature to L. [add "if absent" if you don't want repeats]

But as a general rule, I’ve found you seldom need actual lists (as in the data type) in I7, and it’s often more idiomatic to solve it a different way instead.

lab is a room.

color is a kind of value.

the colors are brown, red, orange, yellow, blue, green, indigo, violet.

a color has a relation of a color to a color called the mixmaster.

to (c1 - color) mixed with (c2 - color) is (c3 - color):
  now the mixmaster of c1 relates c2 to c3;
  now the mixmaster of c2 relates c1 to c3;

to decide what color is (c1 - color) mixed with (c2 - color):
  if c2 relates to a color by the mixmaster of c1, decide on the color that c2 relates to by the mixmaster of c1;

when play begins:
  red mixed with blue is violet;
  say "red + blue = [red mixed with blue].";
  say "blue + red = [blue mixed with red].";
  say "orange + green = [orange mixed with green].";


red + blue = violet.
blue + red = violet.
orange + green = brown.

That’s horrible. I love it.



1 Like

I’d be in there with bitwise operations (1=red, 2=green, 4=blue…) but that’s me.

1 Like

Inspired by @zarf, I came up with this. Not perfect (the secondary colors dominate when mixed with any primary, for example) but you get the idea.

Lab is room.
A color is a kind of value.
white, blue, yellow, green, red, violet, orange, and brown are colors.

To decide what color is (c1 - a color) mixed with (c2 - a color):
	(- (({c1}-1) | ({c2}-1) + 1); -).

When play begins:
	repeat with first running through colors:
		repeat with second running through colors:
			say "[first] mixed with [second] is [first mixed with second].".


I tried to use relations at one point but couldn’t figure out how to make it work (still fairly new to this language and struggling through learning its various features).

@zarf’s bitwise idea feels like the most elegant solution here

1 Like

This is perhaps the most convoluted use of relations I’ve ever seen. Even experienced Inform users generally don’t know that it’s possible! So don’t worry about that part.


Yeah, what Daniel said. My code would compile but not work in 9.3/6M62. To my knowledge, relations as properties don’t work at all before 10.1, and in 10.1’s two years now of existence, I don’t think I’ve seen anyone else use them.

That said, Graham’s 2020 talk at Narrascope put forth:

Inform’s “Everything is an X”: relations and rules
For Inform, there are two big ideas: relations and rules.

I think it’s the case that something like my solution is actually “meant to” be the Inform-ish approach to a problem like this (or, at very least, that there’s a defensible argument for such).

Unfortunately, the docs are so opaque and omit so much detail you need to actually have a shot of knowing what’s possible and how to express that in code, that relations’ use tends toward the simplistic.


And I always find myself wishing there could be more overlap between them…

1 Like