Godot Version
4.4.1
Question
I’m having trouble writing my Player’s inventory to a save file, but only when I am accessing the Player using a list of the current players in the game. When I access the same Player using a static localPlayer variable, it works as expected.
public void SaveGame () {
NonArraySave();
// ArraySave();
if (Player.localPlayer == Player.players[0]) {
GD.Print("THEY'RE THE SAME PERSON");
}
if (Json.Stringify(Player.localPlayer.equipmentManager.SaveCurrentEquipment()).Equals(Json.Stringify(Player.players[0].equipmentManager.SaveCurrentEquipment()))) {
GD.Print("THEY'RE THE SAME STRING");
}
}
void NonArraySave () {
using FileAccess saveFile = FileAccess.Open(fileName, FileAccess.ModeFlags.Write);
string saveString = "NonArrSave\n";
saveString += Json.Stringify(Player.localPlayer.equipmentManager.SaveCurrentEquipment());
saveFile.StoreLine(saveString);
}
void ArraySave () {
using FileAccess saveFile = FileAccess.Open(fileName, FileAccess.ModeFlags.Write);
string saveString = "ArrSave\n";
saveString += Json.Stringify(Player.players[0].equipmentManager.SaveCurrentEquipment());
saveFile.StoreLine(saveString);
}
The only difference between the 2 methods is that the NonArraySave method uses Player.localPlayer instead of Player.players[0], but somehow ArraySave doesn’t work; the save file is just completely empty.
The player is the same and the Json strings being stored are identical but 1 method works and 1 doesn’t. Does anyone know what I could be doing wrong?
I am using Linux Mint if that changes anything.