I have an application that needs to store the scores and playtime of multiple users(to be viewed from outside of the application) and fetch it again to put into charts in a seperate menu screen for graphs/user info. ( max 200 users)
I have tried this with playerprefs but could only figure out how to do this for only the last player, did I save incorrectly or should I do this in a different way, like SQLite or something?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SessionStore : MonoBehaviour
{
public InputField iField;
static public string currentName;
static public int userNumber;
public void CheckUser()
{
Debug.Log(iField.text);
currentName = iField.text;
}
public void SaveStuff()
{
PlayerPrefs.SetString("Name", currentName);
}
public void LoadStuff()
{
currentName = PlayerPrefs.GetString("Name", "");
}
}
This is what I made on a test setup but as you can see it only saves the current Name and loads it
I think what @RoMax92 may have left implied is that you don’t want to store that stuff in PlayerPrefs if you can avoid it. If your target platform supports it, you’ll want to save a file in the persistent data path. You may want to save one file per user or a file with all the users in it. I don’t know which is better for y our situation but I do know that PlayerPrefs has (for me) not been a safe place to store things you want to persist.
Yeah I’m looking into using json right now, seems like a nice solution, since it also saves all the users into 1 file in a readable format. Just gotta figure out how to load in the data per specific user
With JSON, you will almost assuredly use a parser that makes the data look like a nested hierarchy of dictionaries…that’s all anything in JavaScript ever is anyway. So there will probably be a collection of things where the keys are integers (their approximation of an array), you’ll loop through those and find the one with a sub-property (like ID) that has a certain value (like the user’s ID).
It’s kind of like a poor man’s xpath…but, you know, JSON is what the kids are doing, these days, and if you don’t do it, too, everyone will laugh at you.
…and nothing is more important than the approval of your “peers”.
To me it’s like a super player prefs, being able to save everything playerprefs can, but in addition, arrays, custom classes, arrays of custom classes, as long as whatever is being saved is marked serializable.
In practice it’s saving a class to binary, so if you use arrays, that’s your hierarchy right there completely usable on load.
Also interested in hearing it’s downsides from more seasoned devs.