Page 1 of 1

Load Game (PlayerPrefs) via dialogue.

Posted: Tue Sep 06, 2016 5:40 am
by ricjonsu098
Hello, I am using the Dialogue System Menus extra, is there a way to load the saved game via dialogue?

What I want is, when the conversation ends, it will load a saved game. thanks

Re: Load Game (PlayerPrefs) via dialogue.

Posted: Tue Sep 06, 2016 9:28 am
by Tony Li
Hello,

Add a small script with an OnConversationEnd method to the Dialogue Manager. For example, something like:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;
using PixelCrushers.DialogueSystem.Menus;

public class LoadGameOnConversationEnd : MonoBehaviour {
    public void OnConversationEnd(Transform actor) {
        var loadSlot = DialogueLua.GetVariable("LoadSlot").AsInt;
        if (loadSlot >= 0) FindObjectOfType<SaveHelper>.LoadGameInSlot(loadSlot);
    }
} 
I have to emphasize that it will be something like the script above. I'm out of the office for most of the day today, so I can't double-check the syntax right now.

To use this, create a Number variable in your dialogue database named "LoadSlot", and set its value to -1. In your conversation, set the variable to a slot number. At the end of the conversation, this script will load the game in that slot.

Re: Load Game (PlayerPrefs) via dialogue.

Posted: Tue Sep 06, 2016 10:18 am
by ricjonsu098
Thanks, I will try to make it work. Gonna comeback to give a feedback

Re: Load Game (PlayerPrefs) via dialogue.

Posted: Tue Sep 06, 2016 10:42 am
by Tony Li
Sounds good. If you get stuck, let me know. I'll be back in the office later today and can provide more details then.