How do I choose random things with custom values? (Inform 7)

0 votes
53 views
asked May 23 in Authoring by anonymous
edited May 24

So I have a color value defined as follows, with some basic setup information. This is just a test for my curiosity, not any larger project.

Color is a kind of value. A thing has a color. The colors are red, blue, and black.

The Chamber of Secrets is a room. The chair is in the Chamber. The chair is black. The book is a red thing in the Chamber. The chess set is a blue thing in the Chamber.

And I would like to choose a random color, and then a random thing of that color, like so:

Every turn:
let hue be a random color;
say "You see [a random hue thing]."

I have tried several variations on this, and it works if I use a specific color instead of hue. (e.g. a random blue thing). How can I fix this?

1 Answer

+2 votes
answered May 24 by vaporware (56 points)
edited May 24 by vaporware

The quick fix is to change a random hue thing to a random thing that is hue. Silly that you have to do that, but it seems to work.

But I'd recommend defining a relation instead, so it'll be clear what the connection is between hue and the thing:

Coloring relates a thing (called T) to a color (called C) when the color of T is C.
The verb to be colored implies the coloring relation.

Every turn:
    let hue be a random color;
    say "You see [a random thing colored hue]."
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...