Substituting text / phrases / nodes at runtime

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
UKMasters
Posts: 15
Joined: Sun Jun 28, 2020 3:41 pm

Substituting text / phrases / nodes at runtime

Post by UKMasters »

Hi Tony,

This isn't fully thought through yet, as I wanted to check what's possible before going too far down a certain route. So please bear with me.

As part of the game I'm developing, I want to be able to provide variations in the narrative, so that the player can run the same story but different things might happen, and different choices will be triggered depending on what's happened.

A a simple example...The player enters a cave. They can go left or right. They choose left. Reaching the next node causes a process to run to determine what happens (e.g. the node is marked as "variable outcome" somehow). Certain parameters will be passed into the process to restrict the options.

In this example, when the player arrives at the node, the scenario will be picked randomly from a list, such as:
1. Find an item
2. Find a deceased thing
3. Find an alive thing

Let's say the random number is (2) - and the player will find a deceased thing.

Now, the text shown will be procedurally generated by combining things from a "dictionary" of different phrases (originating from a base phrase template) to vary what actually happens.

Base Phrase: You see {deceased figure}{leaning_against}{location.wall}.

Then, another random number generator would build the phrase.

1. You see {the body of a dead elf}{slumped against}{the rough wall of the cave} (if location = cave)
2. You see {the desiccated corpse of a dwarf}{almost hidden, backed up into a crevice in the rock} (if location = cave)

If the location was a forest instead of a cave, different text would be triggered - e.g.
3. You see {a recently deceased elven scout}{pinned to the tree by a number of spears} (if location = forest)

Based on what is found, this will trigger different choices. So, for a deceased thing the choices might be:
1. Loot the body (outcomes: find an item (randomly selected); if "iswithcompanion" is true, then trigger love/hate change)
2. Bury the body (outcome: if "iswithcompanion is true, then trigger love/hate change (e.g. respect)
3. Loot the body and then bury it
4. Ignore the body

Once this "interlude" is over, the player will then resume the pre-constructed narrative.

I am using the Dialogue System to run the main stories in the game. So I would like to find a way to incorporate this kind of thing into the system. Would you be able to provide some guidance on how I could look to do this? (or if there's anything similar already). I'm thinking I can build up a "database" (maybe via scriptable objects) of possible things which would be combined in different ways - and certain options are linked together. So finding the dead body will then have a 50% of producing certain loot, or alternatively might trigger a quest (e.g. to find who killed them).

There will be hundreds and hundreds of variations (based on scenarios, locations and other variables), so I can't see that it's feasible to create dialogues for each combination of things in advance. So I'm hoping it will be possible to find a way to "inject" elements into the dialogue somehow. Thinking about it, maybe one option would be to write a script that produces hundreds of dialogues when initialising, and then divert the player to a random (but appropriate) dialogue before bringing them back to continue the main dialogue. This feels a bit "inelegant" though, so I'm wondering if you can see a better way.

Any ideas?

Thanks
Pete
User avatar
Tony Li
Posts: 22049
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substituting text / phrases / nodes at runtime

Post by Tony Li »

Hi Pete,

It sounds like the interlude scenarios will follow a few similar structures, so you can take a Mad Libs approach. For example, your generic Find a Deceased Thing conversation might be:

madLibsStructure.png
madLibsStructure.png (36.38 KiB) Viewed 209 times

It depends on variables such as THING, POSITION, LOCATION, and ITEM.

Not shown in the example screenshot above is the Script field for the Loot option. This would depend on one or more additional variables such as TARGETFACTION, and the Script field might look something like:
  • Script: ReportDeed("Player", Variable["TARGETFACTION"], "Loot"); PickupItem(Variable["ITEM"])
Before starting the Find a Deceased Thing conversation, set the variables. Example:

Code: Select all

DialogueLua.SetVariable("THING", "the body of a dead elf");
DialogueLua.SetVariable("POSITION", "slumped against");
DialogueLua.SetVariable("LOCATION", "the rough wall of a cave");
DialogueLua.SetVariable("ITEM", "a fine elven sword");
DialogueLua.SetVariable("TARGETFACTION", "Elves");
DialogueManager.StartConversation("Find a Deceased Thing");
Post Reply