save & load multiple script values

Discussion and help for Easy Save 3
Post Reply
hrohibil
Posts: 10
Joined: Thu Aug 19, 2021 5:46 am

save & load multiple script values

Post by hrohibil »

Hello

Please advice¨


How can i achieve to save and load different values from multiple scripts on only one button?

So i have health and player stats on one script, bullet gun ammo on another and etc...

I want when i press the save button it should save all these values in one go.
Is this possible or what is the normal approach here?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: save & load multiple script values

Post by Joel »

To do this you would put multiple save calls in one method. I.e.

Code: Select all

public void MyMethod()
{
	ES3.Save("myVariable1", myScript1.myVariable1);
	ES3.Save("myVariable2", myScript2.myVariable2);
	// etc
}
As this is a question about Unity buttons and programming in general rather than Easy Save, I recommend asking for more information on the Unity forums.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
hrohibil
Posts: 10
Joined: Thu Aug 19, 2021 5:46 am

Re: save & load multiple script values

Post by hrohibil »

Thanks for reply Joel

As mentioned in other post, I have no issue with buttons, I simply could not make it work with the code.
I fixed the player position, thank you so much.
ES3 is truly powerful and nice to use..

However in the below script, i try to implement so when clicking on save, it should save both the player position and his health.
I does not save or load his health.

Please look at my code...

Code: Select all

public void MyMethod()
{
        playerHealth healthBox = pHealth.GetComponent<playerHealth>();

	ES3.Save("currentHealth", healthBox.currentHealth);;
	ES3.Save("playerPos", player.transform.localPosition);
	// etc
}

public void LoadData()
{
         playerHealth healthBox = pHealth.GetComponent<playerHealth>();
         player.transform.localPosition = ES3.Load("playerPos", defaultValue);
         
         ES3.Load<float>("currentHealth");


}

User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: save & load multiple script values

Post by Joel »

Hi there,

There is a programming mistake in your code unrelated to Easy Save. You're not assigning the output of the ES3.Load method to your health variable.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
hrohibil
Posts: 10
Joined: Thu Aug 19, 2021 5:46 am

Re: save & load multiple script values

Post by hrohibil »

I got it to work.

Thank you Joel..

I am loving it more and more as i use it..

I can basically save all that i need :-)

Now i need to figure out how that applies between scenes..

Cheers
Post Reply