Need random room description that doesn't randomize when looking

Seems like this should be a straightforward piece of code but I can’t figure it out.

Here’s the test code:

Lab is a room.

To decide what K is a random member of (list - list of values of kind K):
	let length be the number of entries in the list;
	let index be a random number between one and length;
	decide on entry index of the list.

To decide what text is lab-description-001:
	let description-parts be {
		"Part-001-001.",
		"Part-001-002.",
		"Part-001-003."
	};
	decide on a random member of description-parts.

To decide what text is lab-description-002:
	let description-parts be {
		"Part-002-001.",
		"Part-002-002.",
		"Part-002-003."
	};
	decide on a random member of description-parts.

To decide what text is lab-description-003:
	let description-parts be {
		"Part-003-001.",
		"Part-003-002.",
		"Part-003-003."
	};
	decide on a random member of description-parts.
	
To decide what text is lab-description:
	decide on "[lab-description-001] [lab-description-002] [lab-description-003]".

Fooing is an action applying to nothing.
Understand "foo" as fooing.
Instead of fooing:	
	now description of lab is lab-description.

Test me with "l/foo/l/l/l".

The expected behavior is the description of the room only randomizes when I enter ‘foo’.

The observed behavior is the description of the room also randomizes when I enter ‘l’.

I’ve tried a bunch of permutations:

Instead of fooing:
	now description of lab is "[lab-description]".
Instead of fooing:
	let str be [lab-description];
	now description of lab is str.
Instead of fooing:
	let str be "[lab-description]";
	now description of lab is str.

None of these ideas work. I feel like there is something fundamental I don’t understand about function invocation in this language. Can someone help me with my confusion?

Internally, any text with substitutions is really a piece of code which generates the desired output. That’s what you’re running into. (This is normally the better way to do things, because calling functions and printing text is more efficient than manipulating string data.)

To get what you want, just do this:

Instead of fooing:	
	now description of Kitchen is the substituted form of lab-description.
1 Like

That works, thanks.

Once you gave me the phrase, I was able to look it up and read more about it in the documentation (§20.7. Making new text with text substitutions) as well.

1 Like

FYI, if you want the random choice to be decided once when first printed and then never changed (until the story is restarted entirely), then you can use the [one of]a[or]b[or]c[sticky random] construction.

2 Likes