Save data on mysql database

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
nikot93
Posts: 6
Joined: Thu May 25, 2023 1:33 pm

Save data on mysql database

Post 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ò
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save data on mysql database

Post by Tony Li »

Hi,

Use PersistentDataManager.GetSaveData() and ApplySaveData(). See Database-Only Save for the 3 lines of code you'll need.
nikot93
Posts: 6
Joined: Thu May 25, 2023 1:33 pm

Re: Save data on mysql database

Post 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ò
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: Save data on mysql database

Post 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.
Post Reply