Substring replacement
Substring replacement
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?
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
Hi,
"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.
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.
Use Conditions. Please see the Conversation Conditions Tutorial.
Re: Substring replacement
Thank you very match! That's exactly what i need.
Re: Substring replacement
Glad to help! If other questions come up, let me know.
Re: Substring replacement
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
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".
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
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.
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
Hi,
Yes. You only need to assign a value to create a variable:
Yes. You only need to assign a value to create a variable:
Code: Select all
DialogueLua.SetVariable("My New Variable", 42);
Re: Substring replacement
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?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);
Re: Substring replacement
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);