Hi! I'm interested in writing conversation options and responses directly with scripting, but I'm having trouble finding if that's even possible via the scripting guide (I can pull an existing convo via arrays, but I can't set them?) Is there an example script available of a dialog tree that is written in c#?
Thank you!
- Mo
Comments
int[] idArray = myConversation.GetIDArray ();
ButtonDialog newOption = new ButtonDialog (idArray);
myConversation.options.Add (newOption);
Where "idArray" is an Array of the existing options internal ID numbers. This array is used to generate a new, unique ID number for the new option, which is necessary to manage them together.
For convenience, I'll add a constructor that lets you define the ID number directly, but the code above should work. You can then assign the various fields in the new ButtonDialog class following this page of the scripting guide. However again, I'll see about adding constructors that lets you more easily assign the key fields, such as label text and output DialogOption interaction.
newOption.label = "Test Option";
newOption.customScriptObject = gameObject;
newOption.customScriptFunction ="customResponseFunction";
myConversation.options.Add (newOption);
void OnMouseDown() {
if (KickStarter.dialog.IsAnySpeechPlaying(false) == true){
KickStarter.dialog.KillDialog(KickStarter.dialog.speechList[0]);
}
}
Are you choosing to not wait for the dialogue to finish before showing the Conversation? If you want a "final" line to show at the same time (e.g. Mass Effect-style), you can show it in a Menu whose Appear type is set to Manual instead.
The Active Input is probably responding to the user clicking on the Conversation option as well - so you would need to make it conditional to only work at certain times (during Cutscene gameplay may be enough).
However I wouldn't have thought you'd need to resort to this method. I think we need to back up a post or two because I'm not perhaps fully understanding the issue. Is this a problem with the last dialogue being played before a Conversation, or all dialogue lines? A complete description of the exact behaviour of it all (with your code included) would be very helpful.
Speech lines should handle user input from within - meaning so long as the game is in the Cutscene state, they should respond to user input whether they were called from code or from Actions.
The main thing that separates a single StartDialog function call from the "Dialogue: Play speech" Action is that the Action can be made to wait until the dialogue has finished playing before running the next Action. If you're coding this, you need to make sure the dialogue has finished before running the next Conversation / line. This could be done in a coroutine, ie:
KickStarter.dialog.StartDialog (...);
while (KickStarter.dialog.CharacterIsSpeaking (myCharacter))
{
// Wait before continuing
yield return new WaitForFixedUpdate ();
}
IEnumerator testResponse () {
KickStarter.dialog.StartDialog(KickStarter.player, "Response dialog.", false);
while (KickStarter.dialog.CharacterIsSpeaking (KickStarter.player))
{
yield return new WaitForFixedUpdate ();
}
KickStarter.dialog.StartDialog(KickStarter.player, "Response dialog2.", false);
}
What is the context of this code - where are you calling it from? All of your non-instant code needs to be in a co-routine. Try this adapted script: it'll show a button in the corner that shows two lines that can be skipped:
http://pasteall.org/392782/csharp
newOption.customScriptFunction ? I've tried passing it a string "functionName(var)" but it just tries to run a function with that name. No worries if it isn't possible, just curious if there's a trick to it.
A bit late to the party here, but just a quick thanks to @ChrisIceBox and @MoCohen for this thread, because it enabled me to quickly implement a similar feature in my own current project
As the information is all a bit scattered (and some of it no longer exists), here, for anyone else looking for the general format for scripted dialogues (or similar types of cutscene), is the coroutine that I'm using in my own project. It simply displays a Player statement and an NPC response, and was created after pulling together all the information contained in this thread
It's very simple, but it demonstrates the principles involved. Invoke it using something like:
StartCoroutine(DialogueCutScene(playerChar, playerSays, actorChar, actorSays));
It appears that:
KickStarter.stateHandler.StartCutscene();
KickStarter.stateHandler.EndCutscene();
have been changed to:
KickStarter.stateHandler.EnforceCutsceneMode = true;
KickStarter.stateHandler.EnforceCutsceneMode = false;
is that right?
Correct - see the Changelog's "Upgrade notes" and "API" sections for full details on function/variable changes.