Substring replacement

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Substring replacement

Post by korsak42 »

Hello! I wanna create some kind of procedural generation of dialogs, like "Go to <City-name>, talk with <Character-name>, buy <Item-name>". All names are taken from the database.
Where should i start reading manual to understand how to create this? Can this be done internally by the plugin, or do I need to write the code for this myself?
Also, how to show/hide replies depending on the variables?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Hi,
korsak42 wrote: Tue Jul 19, 2022 9:20 amHello! I wanna create some kind of procedural generation of dialogs, like "Go to <City-name>, talk with <Character-name>, buy <Item-name>". All names are taken from the database.
You can do quite a lot with Dialogue System variables and other database values. You may be able to set it up without writing any code. To fill in text procedurally, use markup tags such as [var=variable] and [lua(code)]. For example:

"Go to [var=Destination_City], talk with [var=Target_NPC], buy [var=Target_Item]."

Alternatively, you can use an OnConversationLine method in C# to manipulate the text before it's displayed.

If you don't want to fill in text procedurally, you can create entirely new conversations. See: How To: Create Dialogue Database At Runtime

In addition, your example looks similar to a quest. (More info: Quests) You can create new quests at runtime, but it does require coding -- either C# or visual scripting such as PlayMaker or Bolt. C# API: QuestLog.
korsak42 wrote: Tue Jul 19, 2022 9:20 amAlso, how to show/hide replies depending on the variables?
Use Conditions. Please see the Conversation Conditions Tutorial.
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Thank you very match! That's exactly what i need.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Glad to help! If other questions come up, let me know.
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Tony Li wrote: Tue Jul 19, 2022 10:26 am
In addition, your example looks similar to a quest. (More info: Quests) You can create new quests at runtime, but it does require coding -- either C# or visual scripting such as PlayMaker or Bolt. C# API: QuestLog.
I've tried to do runtime quest generation, but this:
public void SendQuestToLua()
{
QuestLog.AddQuest("1", "1");
}

public void OnEnable()
{
Lua.RegisterFunction("SendQuestToLua", this, SymbolExtensions.GetMethodInfo(() => SendQuestToLua()));
}

doesn't add any to "Quest/Item" tab. Did i miss something?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Hi,

It won't appear there.

The Quest/Item tab, and all other tabs except the Watches tab (which only appears in play mode) show what's in the dialogue database asset that you're editing.

At runtime, the Dialogue System puts all of that information into its Lua environment so you can manipulate it. Use the Watches tab or a Lua Console to see quests that you've added at runtime. In the Watches tab, select Menu > Add All Quests. In the Lua Console, enter "return Quest".
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Oh, great! Thank you again!
One more question: can i create variables via c#? I searched the documentation for a long time, but didn't find anything similar.
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

Hi,

Yes. You only need to assign a value to create a variable:

Code: Select all

DialogueLua.SetVariable("My New Variable", 42);
korsak42
Posts: 34
Joined: Tue Jul 19, 2022 7:36 am

Re: Substring replacement

Post by korsak42 »

Tony Li wrote: Mon Aug 08, 2022 9:42 am Hi,

Yes. You only need to assign a value to create a variable:

Code: Select all

DialogueLua.SetVariable("My New Variable", 42);
Wow. That's was unexpected. Sorry, forgot to ask: how to delete Lua variables from memory? Wouldn't constant creation of new variables cause memory overflows without deleting them?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Substring replacement

Post by Tony Li »

It's not too likely since variables are small. However, you can delete them by assigning null:

Code: Select all

DialogueLua.SetVariable("My New Variable", null);
Post Reply