Page 1 of 1

Saving and loading during dialogue flow

Posted: Sat May 13, 2017 8:25 am
by hellwalker
Hi,

I want to allow players to save during dialogue and load the conversation back where they left off.
What would be the best way to approach this? I have a lot of dialogue so I'm looking for a way that does not require manual work on each node if possible.



Thanks

Re: Saving and loading during dialogue flow

Posted: Sat May 13, 2017 10:43 am
by Tony Li
Hi,

The GameSaver Example on the Dialogue System Extras page. It includes a RememberCurrentDialogueEntry script that works automatically; it doesn't require anything special on dialogue entry nodes. Although the example uses GameSaver (to make it easy for non-scripters), you can ignore the GameSaver part of the example if you want.

This may not be relevant, but there's also a Backtracking Example to allow players to step backward in conversations.

Re: Saving and loading during dialogue flow

Posted: Wed May 17, 2017 4:12 pm
by hellwalker
Awesome thank you!

As I understand these would re-trigger the sequence commands-right?. So for example if I'm adding 1 to variable, if player reloads the game it will add 1 to variable twice?

I'm thinking of adding custom override for this, how would you recommend I avoid this?
I was thinking of somehow saving dialogue node ID and adding custom Tag for sequencer like [once]. And ignoring the sequence with [once] tag if it's fired a second time.

Re: Saving and loading during dialogue flow

Posted: Wed May 17, 2017 8:27 pm
by Tony Li
If you're adding 1 to a variable, I'm guessing you're using the Script field. The Script field is Lua, which is a real programming language. Instead of this:

Code: Select all

Variable["x"] = Variable["x"] + 1
you could do this:

Code: Select all

if (Variable["set_x"] == false) then 
  Variable["x"] = Variable["x"] + 1
  Variable["set_x"] = true
end
You'll probably want to play the Sequence field even when you reload. For example if it sets up the camera position for the dialogue entry:
  • Dialogue Text: "Look into my eyes..."
  • Sequence: Camera(Closeup)
But if you want to make it run only once, you could write a custom sequencer command that also sets a Lua variable to record that it ran. For example, the Sequence might look like:
  • Dialogue Text: "Look into my eyes..."
  • Sequence: CameraOnce(eyes_closeup, Closeup)
where eyes_closeup is a Lua variable that your custom CameraOnce() command sets and checks.

Re: Saving and loading during dialogue flow

Posted: Sat May 20, 2017 12:48 pm
by hellwalker
Thanks!

I would prefer to avoid making custom variables for each situation where player reloading might break the logic. Is there a way for sequence or for example custom Lua function to get something like dialogue conversation ID + dialogue node ID to use as automatic variable name? Then I could make it universal.

Re: Saving and loading during dialogue flow

Posted: Sat May 20, 2017 2:19 pm
by Tony Li
Hi,
hellwalker wrote:I would prefer to avoid making custom variables for each situation where player reloading might break the logic. Is there a way for sequence or for example custom Lua function to get something like dialogue conversation ID + dialogue node ID to use as automatic variable name? Then I could make it universal.
Yes. If you're using the RememberCurrentDialogueEntry.cs script, it sets these variables (and includes them in saved games):
  • CurrentConversationActor: (string) Name of the current actor.
  • CurrentConversationConversant: (string) Name of the current conversant.
  • CurrentConversationID: (int) Current conversation ID.
  • CurrentEntryID: (int) Current dialogue entry ID in the conversation.
If CurrentConversationID is -1, no conversation is active and none of the other three variables' values have any meaning.

If you're not using RememberCurrentDialogueEntry.cs, you can get the same information from DialogueManager.CurrentConversationState. You can also check DialogueManager.IsConversationActive to check if a conversation is active, DialogueManager.LastConversationStarted to get the title of the last conversation that was started, and DialogueManager.CurrentActor and DialogueManager.CurrentConversant to get the transforms of the current actor and conversant.