Skip to content

Some weird shenanigans going on with data storage #56

Description

@psenakdotsk

So i was working on a settings page for my game and this is the code:
`
using UnityEngine;
using UnityEngine.UI;

public class Settings : MonoBehaviour
{
[System.Serializable]
public class Setting
{
public string id;
public Toggle toggle;
}

public Setting[] settings;

public void MotionBlur(int id)
{
    bool isOn = settings[id].toggle.isOn;
    ChangeSetting("motion_blur", isOn.ToString());
    Debug.Log("Changed to "+isOn);
}

public void ChangeSetting(string name, string value)
{
    bool isGlobal = false;
    Debug.Log("Running set with "+name+":" + value);
    GameJolt.API.DataStore.Set("settings_" + name, value, isGlobal, (bool success) => { Debug.Log(success); });
}

void Start()
{
    for (int i = 0; i < settings.Length; i++)
    {
        Setting setting = settings[i];
        Debug.Log("Loading setting for ID: " + setting.id);
        GameJolt.API.DataStore.Get(setting.id, false, (string value) =>
        {
            setting.toggle.isOn = value == "true";
            Debug.Log("Loaded setting " + setting.id + ": " + setting.toggle.isOn);
        });
    }
}

}
`

But after running it i was able to set it successfully but then it wasnt able to set it back. Even the debug logs said it was false. After setting it to global to check myself on the gamejolt dashboard it was true there but it just was loading as false here. Idk if its an issue of my code but i dont think so so im placing it here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions