How to store a storyline if it represents such a tree: State tree in the game

Where to begin? How to prepare the script? How to go on it? Number and save position (saved_pos + 1)? How, then, to beat the transition to one of the branches?

  • four
    Normal directed graph. And appropriate storage methods. Well, the entourage in a separate table with reference to the node. - Akina

1 answer 1

The entire list of states is stored in one table. id, description
For storage of arrows there are options. For example:
Transition table from_id, to_id


How to go

1. Select the starting state:

 SELECT * FROM State s JOIN Transitions t on t.to_id = s.id WHERE t.from_id is null 

2. Choose a list of further options:

 SELECT * FROM State s JOIN Transitions t on t.to_id = s.id WHERE t.from_id = :current 

3. Repeat step 2 until the option with to_id = null is selected.
The end.