Setting up complicated interrelated randomish texts

So I’ve got a bit in-game that generates a paragraph or two of randomized text. I’d like high variation and also correlation between early and later bits. For example, if the first sentence is “You spot an apple on the shelf.” the second sentence is related to the apple, and makes sense in context.

I’ve got a handle on picking subjects and verbs, but it’s a little complicated routing through the action. Before I do much coding, I wanted to double check that this seems reasonable (code not compileable - only for example purposes):

[code]To say a random paragraph of text:
say “[initial]”.

To say initial:
if a random chance succeeds:
say “Blah! [secondary A]”;
otherwise if a random chance succeeds:
say “Blah. [secondary B]”;
say “Blah? [one of][secondary A][or][secondary B][or][secondary C][at random]”.


Is that the best way to do it? I can sorta imagine something with tables, but I don’t know if it would actually be any easier/cleaner/more flexible, and having a dozen tables for random text gen feels sort of extravagant.

I don’t know about the best way. It’s a perfectly reasonable way to do it. Say phrases invoking more say phrases, with that kind of random selection, covers a great deal of territory.

For the correlation, don’t forget that a say phrase can change game state too. So you might do

To say choose prop:
    now the global-prop is a random prop;
    say "[The global-prop]"

To say chosen prop:
    say "[the global-prop]"

To say initial-sentence:
    say "[choose prop] [one of]falls off a shelf[or]rolls under a table[at random]. You ignore [chosen prop]."

Yeah, there are a lot of moving parts in there beyond the output, which is part of what makes it messy.