Data as String

Discussion and help for Easy Save 3
Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Data as String

Post by Friction »

Hi,

I want to save my data as string to server. When user logged in my game, I will get saved string and create a .json file (JSON serialization and deserialization). Is that possible with Easy Save?
e.g

Code: Select all

using UnityEngine;

public class Test : MonoBehaviour {

string fromJson ;

void Save () 
{
ES3.Save<int>("myFile.json?tag=ES", 3);
fromJson = ES3.LoadRawString("myFile.json");
//Send fromJson to server
}

void Load()
{
//Get fromJson from server
ES3.SaveRaw(fromJson, "yourFile.json");
print(ES3.Load<int>("yourFile.json?tag=ES"));
}
}
BTW, SaveRaw doesn't work with string.
error CS1502: The best overloaded method match for `ES3.SaveRaw(string, ES3Settings)' has some invalid arguments
error CS1503: Argument `#2' cannot convert `string' expression to type `ES3Settings'
error CS1503 Argument 1: cannot convert from 'string' to 'byte[]'
Thanks in advance.

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

Re: Data as String

Post by Joel »

Hi there,

You seem to be getting mixed up between Easy Save 2 and Easy Save 3 methods. You can't use tags in Easy Save 3, and should use the key parameter of Easy Save 3's methods instead.

With regards to the error you're getting, it looks like we're missing an overload, which will be added in the next update. In the meantime, you can work around this by providing an ES3Settings object. i.e.
ES3.SaveRaw(fromJson, "yourFile.json", new ES3Settings());
With regards to saving and loading from a server, this is documented here:
http://docs.moodkie.com/easy-save-3/es3 ... -es3cloud/

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Re: Data as String

Post by Friction »

Hi Joel,

Thanks for your quick reply.
Here my new test script:

Code: Select all

using UnityEngine;

public class Test : MonoBehaviour
{
    public void Testing()
    {
        string fromJson;
        ES3.Save<int>("test_1", 5, "saveFile.txt");
        ES3.Save<float>("test_2", 5.4f, "saveFile.txt");
        ES3.Save<string>("test_3", "Joel", "saveFile.txt");
        fromJson = ES3.LoadRawString("saveFile.txt");
        //Sending fromJson to server and getting again from server
        Debug.Log(fromJson);
        ES3.SaveRaw(fromJson, "ourFile.txt", new ES3Settings());
        Debug.Log("test_1: " + ES3.Load<int>("test_1", "ourFile.txt"));
        Debug.Log("test_2: " + ES3.Load<float>("test_2", "ourFile.txt"));
        Debug.Log("test_3: " + ES3.Load<string>("test_3", "ourFile.txt"));
    }
}
I'm getting this log:
{\"test_3\":{\"__type\":\"System.String,mscorlib\",\"value\":\"Joel\"},\"test_2\":{\"__type\":\"System.Single,mscorlib\",\"value\":5.4},\"test_1\":{\"__type\":\"System.Int32,mscorlib\",\"value\":5}}
But when I use SaveRaw and try to get from new .txt file I'm getting this error message:
FormatException: Expected ',' separating properties or '"' before property name, found '\'.
ES3Internal.ES3JSONReader.ReadPropertyName () (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:62)
ES3Internal.ES3JSONReader.Goto (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3JSONReader.cs:197)
ES3Reader.Read[Int32] (System.String key) (at Assets/Plugins/Easy Save 3/Scripts/Readers/ES3Reader.cs:157)
ES3.Load[Int32] (System.String key, .ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:256)
ES3.Load[Int32] (System.String key, System.String filePath) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:235)
EDIT:
Here is the save files:
Before Load/SaveRaw, saveFile.txt:
{"test_3":{"__type":"System.String,mscorlib","value":"Joel"},"test_2":{"__type":"System.Single,mscorlib","value":5.4},"test_1":{"__type":"System.Int32,mscorlib","value":5}}
After LoadRaw, ourFile.txt:
{\"test_3\":{\"__type\":\"System.String,mscorlib\",\"value\":\"Joel\"},\"test_2\":{\"__type\":\"System.Single,mscorlib\",\"value\":5.4},\"test_1\":{\"__type\":\"System.Int32,mscorlib\",\"value\":5}}
EDIT AGAIN:
I found the reason. It's because of our server. :) Thanks again.

Best regards,

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

Re: Data as String

Post by Joel »

Glad you managed to find the problem, let me know if you bump into any other issues you need assistance with :)

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

Friction
Posts: 6
Joined: Sat Nov 25, 2017 3:14 pm

Re: Data as String

Post by Friction »

Hi again,

I can't decrypt my string data.
I'm trying this:

Code: Select all

string fromJson;
        fromJson = ES3.LoadRawString("saveFile.txt", new ES3Settings(ES3.EncryptionType.AES, "mypass"));
Is LoadRawString method supports decryption? Thanks in advance.

Best regards,

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

Re: Data as String

Post by Joel »

Hi there,

LoadRawString loads the data raw from the file, so does not provide decryption.

If you wish to use decryption, you should use the ES2.Save and ES2.Load<string> methods to save and load the data to a tag within the file, which does support encryption.

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

User avatar
frezno
Posts: 10
Joined: Mon Nov 13, 2017 8:53 pm

Re: Data as String

Post by frezno »

Is there a way to do this without saving out to a file then reading that file? Like maybe saving in memory? I am transitioning my save structure to a server that is not maintained by myself so I can't use ES3Cloud, and saving to a file then reading from the file means there is a possibility of cheating.

Using ES3 because JSON is the future :p
cloudweight

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

Re: Data as String

Post by Joel »

Hi there,

You can write your data to an ES3File, and then use it's LoadRawString method to return it as a string.

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

User avatar
frezno
Posts: 10
Joined: Mon Nov 13, 2017 8:53 pm

Re: Data as String

Post by frezno »

Oh awesome I didn't even know about ES3File.. I should do some more looking .

While ES3File will work, I wonder how I'll go about loading the Json string back from the server to ES3.
cloudweight

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

Re: Data as String

Post by Joel »

Hi there,

I've added some constructors to the ES3File class which accepts a string or a byte array, which I'll PM to you now. Simply use it to the replace the ES3File.cs file in Assets/Plugins/Easy Svae 3/Scripts/.

All the best,
Joel
Joel @ Moodkie Interactive
Buy Easy Save | Contact | Guides | Docs | Getting started

Post Reply