Page 1 of 7

Substring replacement

Posted: Tue Jul 19, 2022 9:20 am
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?

Re: Substring replacement

Posted: Tue Jul 19, 2022 10:26 am
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.

Re: Substring replacement

Posted: Tue Jul 19, 2022 10:38 am
by korsak42
Thank you very match! That's exactly what i need.

Re: Substring replacement

Posted: Tue Jul 19, 2022 10:54 am
by Tony Li
Glad to help! If other questions come up, let me know.

Re: Substring replacement

Posted: Sun Aug 07, 2022 8:26 pm
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?

Re: Substring replacement

Posted: Sun Aug 07, 2022 9:34 pm
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".

Re: Substring replacement

Posted: Mon Aug 08, 2022 5:57 am
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.

Re: Substring replacement

Posted: Mon Aug 08, 2022 9:42 am
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);

Re: Substring replacement

Posted: Mon Aug 08, 2022 12:39 pm
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?

Re: Substring replacement

Posted: Mon Aug 08, 2022 1:29 pm
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);