#About JSON file writing
1 messages · Page 1 of 1 (latest)
Resource and StreamingAssets both are for read-only purpose
There is persistentDataPath for writing, but I don’t think you need to write file at all for your case
got it, i thought resources could be edited
ok
persist generates a new file in a different folder right?
yes, because it depends for the match
I can't let the player own cards that aren't in their database
I think I got it, so I can read the file and create a new file with persist, and modify the rest of my code to fetch the information from this new json, correct?
Yes that would be the way
Your original file is design data and the other one is progress/save data
If I understand your intention correctly
I think so
string newDeck = Resources.Load<TextAsset>("Decks/Hell").ToString();
BinaryFormatter formatter = new BinaryFormatter();
string way = Application.persistentDataPath + "/Hell.json";
FileStream fileStream = new FileStream(way, FileMode.Create);
formatter.Serialize(fileStream, newDeck);
fileStream.Close();```
my code for create the new json
I will implement to overwrite and change the paths of the rest of the code to see if it works, 1 moment
have a problem using File.WriteAllText? ```c++
public void AtualizaJsonDeck(string data){
string path = Application.persistentDataPath + "/Hell.json";
File.WriteAllText(path, data);
Debug.LogFormat ("[EasyDeckEditor] Saved {0} successfully.", pathDeck);
Debug.LogFormat ("[EasyDeckEditor] Data {0}.", data);
}```
But is copying whole card data what you want, or you just need list of cards/changes of user?
WriteAllText should be okay to do
the way I thought of doing it is every time I start the game, delete the file in the persist if it exists and create a new one so that I feed it with the user's cards again
keeping it up to date whenever you enter the game
bad idea?
If you already have up to date information, and if you are not going to read from file, then why do you need save it as file?
That what I don’t understand
It seems like you already have databse and it is where the data saved
Can you think of actual example data for original file and modified file that you would save? 🤔
Because currently the rendering of the cards on the table depends on Json files, I will implement it to pull directly from the database, but at the moment we are in a hurry to launch a beta
That makes more sense now
If that is the case this scenario makes sense
Is it problem with saving json?
I'm not sure, in the editor it still logs normally, but in the build it doesn't do anything and doesn't even accuse an error.
yes, I disabled the method that makes the update to test
same thing, at least I know it's not that, the hard thing now is to find out lol
Is there any reason for the script execution to work in the editor but not in the build?
I found the problem, it was my stupidity, I switched scenes and forgot to update in the build settings, so in the editor I tested one and in the build I tested another scene 🤦♀️
thank you very much for your attention and help, here it is solved