Creating c# script for persistence data and the feature demo.
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Creating c# script for persistence data and the feature demo.
Good day!
How to create a persistence data script for variables?
The variables are:
Money as int
Mathematics as bool
Achievement as bool.
Also for the feature demoscript.
I'm using the feature demo script because I'm trying to create my own prefab for the main menu. Now, it's working, but there's i wanted to try. Making the menu open by the button. My question is how to make the feature demo script to be open using the button?
Thanks for the help in advance.
How to create a persistence data script for variables?
The variables are:
Money as int
Mathematics as bool
Achievement as bool.
Also for the feature demoscript.
I'm using the feature demo script because I'm trying to create my own prefab for the main menu. Now, it's working, but there's i wanted to try. Making the menu open by the button. My question is how to make the feature demo script to be open using the button?
Thanks for the help in advance.
Re: Creating c# script for persistence data and the feature demo.
You can either start with a copy of PersistentDataTemplate.cs or just add OnRecordPersistentData() and OnApplyPersistentData() methods to your existing script. For example:HaiiroMukuro wrote:Good day!
How to create a persistence data script for variables?
The variables are:
Money as int
Mathematics as bool
Achievement as bool.
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class MyScript : MonoBehaviour {
public int Money;
public bool Mathematics;
public bool Achievement;
void OnRecordPersistentData() {
// Before saving game, record variables into Dialogue System's Lua environment:
DialogueLua.SetVariable("Money", Money);
DialogueLua.SetVariable("Mathematics", Mathematics);
DialogueLua.SetVariable("Achievement", Achievement);
}
void OnApplyPersistentData() {
// After loading game, retrieve variable values from Lua:
Money = DialogueLua.GetVariable("Money").AsInt;
Mathematics = DialogueLua.GetVariable("Mathematics").AsBool;
Achievement = DialogueLua.GetVariable("Achievement").AsBool;
}
}
Edit FeatureDemo.cs, and change line 70 from:HaiiroMukuro wrote:Also for the feature demoscript.
I'm using the feature demo script because I'm trying to create my own prefab for the main menu. Now, it's working, but there's i wanted to try. Making the menu open by the button. My question is how to make the feature demo script to be open using the button?
Thanks for the help in advance.
Code: Select all
private void SetMenuStatus(bool open) {
Code: Select all
public void SetMenuStatus(bool open) {
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Re: Creating c# script for persistence data and the feature demo.
It work! Thank you, have a good day!
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Re: Creating c# script for persistence data and the feature demo.
Good day!
How to reset variables?
For example, I play the game and manage to get 50 coins. Then after getting some coins, I decided to click main menu and start the game again.
But the problem is everytime I start the game. The 50 coins that I collected previously still there.
My problem is how to reset the variables?
Thank you and have a great day!
How to reset variables?
For example, I play the game and manage to get 50 coins. Then after getting some coins, I decided to click main menu and start the game again.
But the problem is everytime I start the game. The 50 coins that I collected previously still there.
My problem is how to reset the variables?
Thank you and have a great day!
Re: Creating c# script for persistence data and the feature demo.
Hi,
If you're using a GameSaver component, you can use GameSaver.RestartGame(). If your scene also has a LevelManager, it will call LevelManager.RestartGame() (see below). Otherwise it will just reset the database.
If you're using a LevelManager component without GameSaver, you can use LevelManager.RestartGame() to reset the database and load the default starting level set in the LevelManager component.
If you're using neither GameSaver nor LevelManager, use DialogueManager.ResetDatabase() to reset the variables.
If you're using a GameSaver component, you can use GameSaver.RestartGame(). If your scene also has a LevelManager, it will call LevelManager.RestartGame() (see below). Otherwise it will just reset the database.
If you're using a LevelManager component without GameSaver, you can use LevelManager.RestartGame() to reset the database and load the default starting level set in the LevelManager component.
If you're using neither GameSaver nor LevelManager, use DialogueManager.ResetDatabase() to reset the variables.
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Re: Creating c# script for persistence data and the feature demo.
Hello, am I doing right?
I'm using the game saver right now also I have a question. It will reset the playerprefs? I hope not.
Thanks for the help!
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ResetGame : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
}
public void ResetData()
{
GameSaver.RestartGame();
}
}
Thanks for the help!
Re: Creating c# script for persistence data and the feature demo.
Hi,
Try this:
It will not clear your PlayerPrefs.
Try this:
Code: Select all
FindObjectOfType<GameSaver>().RestartGame();
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Re: Creating c# script for persistence data and the feature demo.
Still not working. What if I use this one?
Code: Select all
public void ResetData()
{
FindObjectOfType<DialogueManager>().ResetDatabase();
}
Re: Creating c# script for persistence data and the feature demo.
Try this:
Code: Select all
public void ResetData()
{
DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
}
-
- Posts: 80
- Joined: Sun Jul 17, 2016 3:38 pm
Re: Creating c# script for persistence data and the feature demo.
It's working! Thanks for the help. I appreciate it. Have a great day!