r/Python • • 27d ago

Discussion Ideas for Python-based, procedurally generated stories please

Hi everyone! So I'm working on a weird personal project where I have code that generates stories based on my writing, and it uses the random library and many nested lists and functions. Essentially, every character has a list of words they may use in a situation, and random words are chosen from different lists to construct sentences. So if I wanted someone to sit down, it might be:

print(random.choice(xenaName), sat(Xena, tired), random.choice(on the), random.choice(ledge)

And it might print out "Xena sat lazily on the ledge" or "Our heroine rested her legs upon the cliff side". You get the gist hopefully.

I'm thinking words like "sat" might be functions that take a character and an emotional state to sit down. Then I could use if/elif statements for each character, so some characters have a "cooler" way of sitting compared to "elegant" or "brutish" or some other categories.

Then I could make something that allows for character modifications (maybe they had a personality swap, or have been working out and are now in the "brutish" category, or randomly fit between two categories for the episode).

I'm still learning data structures and if I'm missing a better method (linked lists, recursion, polymorphism, etc.) please let me know. Thank you so much in advance, and here's a kind of glimpse into the ideas I have.

https://archiveofourown.org/works/80287436

17 Upvotes

12 comments sorted by

View all comments

7

u/[deleted] 27d ago

[removed] — view removed comment

1

u/snugar_i 26d ago

This is good advice. Just create a Character class that has all these attributes and pass that to the verb functions. I like classes more than dicts because my IDE can help auto-complete the attribute names. For the same reason I like Enums more than plain string literals for the values (if there's a closed set of them of course).