Page 1 of 1

Save data on mysql database

Posted: Sun Jun 11, 2023 7:57 pm
by nikot93
Hi,

in my game I save all the data in a mysql database, now that I have integrated the dialogue system plugin I would also need to save the variables and the status of the quests.
How could I do?


Thanks
Nicolò

Re: Save data on mysql database

Posted: Sun Jun 11, 2023 8:50 pm
by Tony Li
Hi,

Use PersistentDataManager.GetSaveData() and ApplySaveData(). See Database-Only Save for the 3 lines of code you'll need.

Re: Save data on mysql database

Posted: Tue Jun 13, 2023 4:46 am
by nikot93
Thanks it work really well!

There is a method to execute this function on every change made in the database (variable change or quest status)?

public void SaveDB()
{
string username = UserData.Instance.Username;
string authToken = UserData.Instance.Token;

StartCoroutine(SaveDatabase(username, authToken));
}


Nicolò

Re: Save data on mysql database

Posted: Tue Jun 13, 2023 8:46 am
by Tony Li
Yes for quest state. Use OnQuestStateChange.

No for variables. A common way to do this is to use OnConversationEnd and save variables when a conversation has ended.