Page 1 of 1

Save Bolt variable in Dialogue System

Posted: Thu Nov 11, 2021 10:35 am
by VietLinh
Hello Tony,
I'm very new in Unity and i don't know about C# script.
I want to save bolt variable in dialogue system. Because Playerprefs of Bolt not encrypt.
I think i can use lua variable to sent bolt variable to save. But if i want save list[int] or list[string] i must create many lua variable...which other way to save bolt variable in dialogue system?

PS: I'm not native English. Maybe something i write not exactly. Sorry about that!

Re: Save Bolt variable in Dialogue System

Posted: Thu Nov 11, 2021 10:57 am
by Tony Li
Hello,

If you want to encrypt data in PlayerPrefs, use this open source code: SecurePlayerPrefs.

If you can put your list in a larger structure, you can use JsonUtiity to serialize (convert) the list into a string and back again. Example structure:

Code: Select all

using System;
using System.Collections.Generic;

[Serializable]
public class MyData
{
    public List<int> myNumbers;
}
If you have an object whose type is MyData, then in Bolt you can use UnityEngine.JsonUtility.ToJson to convert it to a string. Then you can store that string in a Dialogue System variable.

To retrieve the object from the Dialogue System, use UnityEngine.JsonUtility.FromJson.

Re: Save Bolt variable in Dialogue System

Posted: Thu Nov 11, 2021 10:19 pm
by VietLinh
>If you can put your list in a larger structure, you can use JsonUtiity to serialize (convert) the list into a string and back again. Example structure:
As said above, I don't know how to code in c#
Can you give me a specific example?
For example, I have a list variable in bolt (this variable belongs to the player object):
Image
how can use JsonUtiity to serialize (convert) the list into a string and back again

Re: Save Bolt variable in Dialogue System

Posted: Thu Nov 11, 2021 11:02 pm
by Tony Li
Hi,

It will probably be easiest if you put each list element into a separate DS variable.