How Can I set an auto Save/Load stuff?

Announcements, support questions, and discussion for the Dialogue System.
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

How Can I set an auto Save/Load stuff?

Post by ironmanman »

Hi! Masters,

Now I am making a simple version type game like Lifeline. It's just a dialogue game.
I am just wondering how can i set the save and load fuction. It just save and load the current dialogue data.

it goes like:

1. The game can auto save the current dialogue line data.
2.When I start the game , it loads and starts from the last line I chose.
3. When the game is over,it restarts.

I add RememberCurrentDialogueEntry to Dialogue Manager and GameSaver to an empty object. Is there anything else? But I don't want set buttons to call the save and load fuction. :cry:

Or Should I write c sharp codes and attatch it to the empty GameObject:

void Start() {

//Load the last current line?

}

void Update(){
//Save the current line?
}

Please Help ME! Thank you so much! :roll:
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How Can I set an auto Save/Load stuff?

Post by Tony Li »

Hi,

Here's an example scene: AutoSaveLoad_2017-04-09.unitypackage (removed)
Updated scene: AutoSaveLoad_2017-04-15.unitypackage

I'll also put it on the Extras page.

It uses this short script:

AutoSaveLoad.cs

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;

public class AutoSaveLoad : MonoBehaviour
{

    [ConversationPopup]
    public string conversation = "Main Conversation";

    IEnumerator Start()
    {
        // Try to load the saved game:
        FindObjectOfType<GameSaver>().LoadGame();

        // Wait 3 frames for GameSaver to load the game:
        yield return null;
        yield return null;
        yield return null;

        // If GameSaver didn't resume a saved conversation, start from the beginning:
        if (!DialogueManager.IsConversationActive)
        {
            DialogueManager.StartConversation(conversation);
        }
    }

    void OnApplicationQuit()
    {
        // Save the game when quitting:
        FindObjectOfType<GameSaver>().SaveGame();
    }

}
Here are the steps I used to set it up:

1. On the Dialogue Manager, I added:
  • Game Saver
  • Level Manager (in case your game changes scenes)
  • Remember Current Dialogue Entry script
  • Auto Save Load script (which has a dropdown to select your conversation)
2. Created a test conversation named "Main Conversation".

I also included a menu item script Tools > Clear PlayerPrefs that you can use to clear the saved game.
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

Re: How Can I set an auto Save/Load stuff?

Post by ironmanman »

Hi! Tony!

Wow! You are amazing!!! Thanks again!!You made me confidence!! haha

thank you! I will try!

: )
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

Re: How Can I set an auto Save/Load stuff?

Post by ironmanman »

Hi!Tony!!

It really works!! It's great !!!! Love you!

: )
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

Re: How Can I set an auto Save/Load stuff?

Post by ironmanman »

Hi ! Tony ,

The auto saving function works.But there is another issue.

My game has two scenes-- Gameplay and GameEnds.

The game can be saved automatically. But when I loaded scene GameEnd during the game,I quit the game. After I click tbe Play button in Unity3d,Unity3d loaded the two scenes in the same time !There were GamePlay and GameEnd in the hierarchy. The views in game was overlapping. The 2 scenes should be loaded one separately.

How can I fix this?

Thank you!
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How Can I set an auto Save/Load stuff?

Post by Tony Li »

Hi,

Which scene(s) contains your Dialogue Manager GameObject?

How does your game switch from Gameplay to GameEnds?
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

Re: How Can I set an auto Save/Load stuff?

Post by ironmanman »

Tony Li wrote:Hi,

Which scene(s) contains your Dialogue Manager GameObject?

How does your game switch from Gameplay to GameEnds?
Dear Sir Tony,

The scene-GamePlay contains the Dialogue Manager GameObject.

I attached Start Sequence On Dialogue Event component to the empty GameObject-Player. After the player's line comes to an end,the scene swiches from GamePlay to GameEnd.

There is a button in GameEnd. Click it, the scene swiches to GamePlay again. And the game restarts again. In the GameEnd Scene, I attached LevelManager to a empty GameObject-Load Level(GamePlay). This works fine. Play the game -End- Play agian -End. Nice Loop.

But everytime I quit the game and reboost the game again,the two scenes do not overlap. I found out the scene starts from GameEnd. It should start from GamePlay. The original dialogue panel remains because it has the Do Not Destroy funcion. So they looks like they are overlapping. Just like the picture I attached, the game starts frome GameEnd.

Please~~Help me: ) You are the best!!
Attachments
GamePlay-Player-Start Sequence.jpg
GamePlay-Player-Start Sequence.jpg (145 KiB) Viewed 2426 times
GamePlay-Dialogue Manager.jpg
GamePlay-Dialogue Manager.jpg (176.62 KiB) Viewed 2426 times
After quit the game and Play again. It Should start from GamePlay.
After quit the game and Play again. It Should start from GamePlay.
After Restart the game-it begins from GameEnd.jpg (221.23 KiB) Viewed 2426 times
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How Can I set an auto Save/Load stuff?

Post by Tony Li »

Hi,

The game saves the current level. If you quit when you're in GameEnd, that's where the game will resume when you restart.

Here's an updated example: AutoSaveLoad_2017-04-15.unitypackage

It contains a subfolder with scenes named GamePlayTest and GamePlayEnd. To test them, add them to your build settings.

This is how I set it up:

1. I updated AutoSaveLoad so it only saves the game if the AutoSaveLoad component is enabled.

2. I added a new script named GameEndScript and added it to a GameObject in the GameEndTest scene. (I added it to the Restart button.) This script does these things:

2a. When it starts (that is, when the GameEndTest scene starts), it disables AutoSaveLoad. This way, if the player quits the game, it won't save the game in the GameEndTest scene.

2b. When another scene loads, it re-enables AutoSaveLoad.

2c. The script provides a LoadLevel method. You can use this instead of having to add a LevelManager to your scene to call LevelManager.LoadLevel.
ironmanman
Posts: 16
Joined: Tue Apr 04, 2017 10:10 am

Re: How Can I set an auto Save/Load stuff?

Post by ironmanman »

Hi! Sir Tony,

I just tried the updated example: AutoSaveLoad_2017-04-15.unitypackage. I added the GamePlayTest and GameEnd Scenes to the building setting.

When I clicked Play button in Unity, the game still starts from GameEnd. So I can still see the Dialogue panel and game end panel at the same time.

Tools---Reset Playerprebs can not clean the save data. After clicking it, the game still start from GameEnd scene.

Ah!!

I figured it out . It's the component-Start Sequence On Dialogue Event(OnConversation, OnEnd-LevelLoad(GameEnd)). If I delete it ,the game won't start from the GameEnd scene.But It shouldn't be deleted. Could you please modify the component?

Thank you!

P.S. I deleted Start Sequence On Dialogue Event. Set the Dialogue Database-Dialogue Entry-All Fields-Sequence=LoadLevel(GamePlay) on the end of Player's line. It works!!!
Attachments
AutoSaveLoad 2017-04-17 14.14.18.png
AutoSaveLoad 2017-04-17 14.14.18.png (169.06 KiB) Viewed 2418 times
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: How Can I set an auto Save/Load stuff?

Post by Tony Li »

Hi,

Just making sure -- you have a solution that works now, correct?

If not, you could define a Boolean variable in your dialogue database. In the dialogue entry node that ends the conversation, set this variable true.

Then in your Start Sequence On Dialogue Event component, set the Condition so that it only loads GameEnd if the variable is true.

In GameEnd, use a LuaTrigger (OnStart) to set the variable back to false.

Thanks for your patience in working out this issue.
Post Reply