Currently I have this function that loads an integer from a JSON file, and then it sets the ExeBalance to the Integer it found in the JSON file however when checking the breakpoints I see that the JSON JBalance gets retrieved correctly, but it won't change the ExeBalance integer.
It is setting it to the JSON object, but It won't change the ExeBalance value:
ExeBalance = saveDataJson.JBalance;
This is my code:
namespace Money_Simulator
{
public class DataObject
{
public int JBalance { get; set; }
}
internal class DataHandler
{
public int ExeBalance = 0;
public void AddBalance(int amt)
{
ExeBalance = ExeBalance + 1;
Console.WriteLine(ExeBalance);
}
public void LoadSave()
{
string filePath = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"savedata.json"
);
StreamReader sr = new StreamReader(filePath);
string saveDataContent = sr.ReadToEnd();
var saveDataJson = JsonConvert.DeserializeObject<DataObject>(
saveDataContent
);
ExeBalance = saveDataJson.JBalance;
Console.WriteLine("ExeBalance was set to this value from reading savedata.json:");
Console.WriteLine(ExeBalance);
}
}
}
The contents of savedata.json are {"JBalance": 5}.