3
\$\begingroup\$

I have been having issues with managing a conversation tree. I am using PAWN as a scripting language (I have no other options, unfortunately) and I use MySQL databases to store user and game data.

My current issue is storing game conversation trees using SQL. Currently, I have the following table:

TABLE NAME: dialogue
ID: global ID of conversation option
Prompt: question or sentence shown on player's screen
Answer: NPC's answer
[some other stuff related to conditions and mood checks, etc.]

Now, my problem is the following. Suppose I greet the NPC, this would be something like this:

ID: 1
Prompt: Hello there.
Answer: Hi, how's it going?

I want my conversation tree to progress after the player greets the NPC. This is not problematic, I simply use an additional SQL table for that:

TABLE NAME: dialoge_unlock_lock
ID: global ID of dialogue element
Unlocks: option this element unlocks
Locks: option this element locks.

My problem is the following: suppose I greeted the NPC, this would unlock 5 conversation options for the player to choose from (they would have IDs 2-6 for this NPC, and perhaps 241-245 for another NPC). I choose question #2, this would unlock question #8 and lock question #7.

How could I check what questions the player has locked in the current dialogue tree? In this example, I don't want the player to just see question #8, but I want him to see every question that is currently available to him (that is, questions 2-6 & 8).

I have been sitting on this for days and I can't figure out a way to do it. This pretty much sums up my attempts, any help would be greatly appreciated.

\$\endgroup\$
1
\$\begingroup\$

Because you say you use MySQL to store user data, I'd imagine that you'll want to use it to store which questions are locked/unlocked, as the player interacts with the game.

In that case, you'd have some tables to represent the state of the player. Something simple like:

TABLE NAME: unlocked_options
ID: global ID of options unlocked

TABLE NAME: locked options
ID: global ID of options locked

In this way, as the player makes choices, you add and remove lines to those tables. Then you query them to present the player with the right options.

If you don't want to store the state in the database, then you'll have to keep track of it in memory, using a Pawn data structure. Two simple arrays should do the trick, one for locked, one for unlocked, and again you add and remove IDs are the player progresses. If you don't need the persistence of the database, this might be a faster alternative.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.