How to store data?

Hi. I need store data that will the code memory. For example: You are playing game and you need to save your position, but you can't obviously store that in code. Where should I store data?
9 Replies
♡Mr. L0stík♡
♡Mr. L0stík♡OP13mo ago
I thought JSON can help me, but it's too hard.
Angius
Angius13mo ago
A JSON file should be perfectly fine Make a class to represent your saved data Then File.ReadAllText() to read the file, JsonSerializer.Deserialize<TheClass>() to turn it into an instance of the class JsonSerializer.Serialize() and File.WriteAllText() to save the changed settings Ez
♡Mr. L0stík♡
♡Mr. L0stík♡OP13mo ago
Okay, do you have some good tutorial? I just need to get number of level and then re-write to new And I can't find some good tutorial for just this
Angius
Angius13mo ago
Quite literally just what I wrote could serve for a tutorial
class Settings
{
public int Foo { get; set; }
}

var read = File.ReadAllText("settings.json");
var settings = JsonSerializer.Deserialize<Settings>(read);

settings.Foo = 69;

var write = JsonSerializer.Serialize(settings);
File.WriteAllText("settings.json", write);
class Settings
{
public int Foo { get; set; }
}

var read = File.ReadAllText("settings.json");
var settings = JsonSerializer.Deserialize<Settings>(read);

settings.Foo = 69;

var write = JsonSerializer.Serialize(settings);
File.WriteAllText("settings.json", write);
'Ere
♡Mr. L0stík♡
♡Mr. L0stík♡OP13mo ago
Ok, thanks
nukleer bomb
nukleer bomb13mo ago
Yeah, JSON is the easiest way to go. But if you have a lot of data and need to be compact and performant, then you can try using some binary serializer
nukleer bomb
nukleer bomb13mo ago
GitHub
GitHub - Cysharp/MemoryPack: Zero encoding extreme performance bina...
Zero encoding extreme performance binary serializer for C# and Unity. - GitHub - Cysharp/MemoryPack: Zero encoding extreme performance binary serializer for C# and Unity.
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
nukleer bomb
nukleer bomb13mo ago
MessagePack is still better if you need to interop with other languages
Want results from more Discord servers?
Add your server