Login
Remember
IF Answers
Ask a Question

# 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?

- programming
- inform7

## 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]."

## Related questions

- How do I debug in Inform 7?
- How can I prevent appending (open), (closed) etc. to an object in Inform 7?
- How do I find the default parser verbs in Inform?
- How do you test whether the player's interpreter will support windows created with Flexible Windows? (Inform 7)
- How do you avoid an extra line break when refreshing a window with Flexible Windows (Inform 7)?

...