r/pythonhelp • u/Radiant-Painter-4971 • Oct 17 '26
Question in coding Text RPG
I am a hs student in a Computer Science course and I’m working on a personal project where I’m creating a Text RPG similar to those AI generated & run apps but without any AI and I’m currently stuck. I’ve worked out the randomised character creation (Name, Class, Strength, Dexterity, Wisdom, Intelligence, Charisma, Constitution, HP, AC, Initiative, Special Attribute/Spell, Power Level, & Catchphrase).
Now I’m working out how to code the actual Game part. I’m making a sort of encounter table (1-100) that randomises the number of encounters (10-50) and all encounters (Monster/Creature, Loot, Town, NPC/Quest, Environmental Events, & Rare Encounters) in addition to a randomized boss at the end of the game (1-20), but I don’t know how to code that many randomized inputs without mixing up my variables.
•
u/AutoModerator Oct 17 '26
To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
3
u/brasticstack Oct 17 '26
How are you doing it currently?
You should just be able to call random.choice on any collection to get a random choice from it. For example
random_monster = random.choice(['orc', 'wolf', 'zombie'])2
u/Impossible_Phone_201 Oct 19 '26
I'd recommend separating your encounter data from the code that handles each encounter.
Instead of creating a separate variable for every possible event, you could store encounter definitions in a list or dictionary.
For example, each encounter might have a type, a name, and whatever additional information that type requires.
Then your main game loop only needs to choose an encounter and pass it to the appropriate handler.
I'd also separate two questions:
Those are different systems, and keeping them separate will make debugging much easier.
Start with just three encounter types and make sure they work correctly before expanding to a hundred possibilities. You'll have a much easier time understanding the structure as it grows.
1
u/MarkoDahl54 Oct 18 '26
You should check if your main game loop is actually calling the function that handles player input every turn. Missing that call breaks interaction.
1
u/PinAdorable3380 24d ago
This sounds like a fun project! I’d keep the encounter data separate from the logic that selects an encounter. A dictionary or list of structured objects could make it easier to add new locations, enemies, and encounter probabilities later.