How can I structure dialogue data to remember past choices in an RPG?
#1
I’ve been trying to implement a basic dialogue tree for my RPG prototype, but I’m stuck on how to cleanly handle branching choices without my script becoming a tangled mess of if-statements. What’s a good way to structure the data so a conversation can remember a player’s earlier decisions?
Reply
#2
I built a data driven dialogue graph. Each node has an id, the line, and a list of options. Options carry the target node id, a label, and an optional condition set that refers to a story state object. The story state is just a light bag of flags and counters that persist as you move around. The trick is to keep decisions out of the node scripts and keep a separate memory map. When you talk to someone you evaluate which options are available by checking the flags, not a maze of ifs. If you need more structure, you give each node a required state slice like { helpedVillager: true, finishedQuest: false } and you push the chosen option onto a log and mutate the story state.
Reply
#3
I tried something similar with a table of states and it quickly turned into glue between branches. The engine walking the graph felt brittle once I added a new choice; I ended up refactoring to keep the data and the logic separate.
Reply
#4
A concrete action I took was to store memory in a small dict and encode branches as requirement lists. Each option had needs: [ 'loyaltyHigh', 'questA_done' ]; the engine checked those keys before showing the option. After selection, I updated a few counters: loyalty += 1, reputation changes. It helped avoid a wall of ifs but it still requires discipline to not duplicate lines.
Reply
#5
One question: do you actually need memory across scenes, or is this local to the current conversation?
Reply


[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Forum Jump: