Doubly-linked list

I have a kind of thing with a special text variable. This text variable has a number of possible values; what values those are depends on the specific object, and different objects have different numbers of possibilities. Certain actions can also shift this text “left” or “right”, to the previous or next value.

What would be an elegant way to implement this? I’ve been thinking in C++ too much recently it seems; my immediate thought is creating some sort of doubly-linked list, but pointer manipulation in I7 would be a nightmare. And using a list and a numerical offset would work, but feels inelegant. Is there a better way?

I’m not absolutely positive what you’re doing, and in particular whether each of these things has its own possible list of values or whether a bunch of things share lists (so that it would be wasteful to keep multiple copies of the lists).

But if everything has a unique set of values, so that there’s nothing wrong with keeping separate copies of the lists, I suspect that the thing that would be most elegant way would be to rotate the list and check the first entry. At least, this would be most elegant in the sense of requiring the fewest words of I7 code. It might be pretty wasteful if you have lots of lists or you’re doing a lot of list rotation; if that’s a concern maybe you’d want to go with a numerical offset.

[code]A zoetrope is a kind of thing. A zoetrope has a list of texts called the readout list. The description of a zoetrope is usually “It displays [entry 1 of the readout list of the item described].”

Turning it left is an action applying to one thing. Understand “turn [something] left” as turning it left.
Turning it right is an action applying to one thing. Understand “turn [something] right” as turning it right.

Zoetropery is a room.

The blue zoetrope is a zoetrope in zoetropery. The readout list of the blue zoetrope is {“a star”, “a square”, “a circle”, “a triangle”}. The red zoetrope is a zoetrope in zoetropery. The readout list of the red zoetrope is {“a slab”, “a block”, “a pillar”}.

Check turning it left when the noun is not a zoetrope: say “You can’t turn that left.” instead.

Check turning it right when the noun is not a zoetrope: say “You can’t turn that right.” instead.

Carry out turning a zoetrope left:
rotate the readout list of the noun;
try examining the noun.

Carry out turning a zoetrope right:
rotate the readout list of the noun backwards;
try examining the noun.[/code]

(The last section of the List chapter in Writing with Inform talks about rings, which is where I got this idea.)

I never thought I’d see someone doing data structures like this with Inform7.

Matt, that’s an excellent idea. The only difficulty is keeping “bounds” on the list, but I can manage that with a sentinel value.

Ah, for some reason I thought you wanted it to wrap.