Hello, I was just wondering when you build a game for the PC/Mac standalone (specifically talking about PC), is it possible to have a .txt file or a .ini file that can be inside the data folder of the game? I want players who use it to be able to edit the file like having some sort of highscore save that can be modifiable in a .txt or have other settings in an .ini. I think it would be cool.
Is this possible? If so, how can I use it and how can I reference the file(s) in-game?
You can have 2 solutions :
First one use something like this :
public static void Save( SaveData data, string filePath )
Stream stream = File.Open( filePath, FileMode.Create );
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Binder = new VersionDeserializationBinder();
bformatter.Serialize( stream, data );
But this cannot be edit by a user cause the file is encrypt. Cause it contains one class composed of some data structs
- Second thing that you can do is to save your data as text in a file by using File.Open( yourFile ). Open function create the file if it doesn’t exists. And then save your data as text so don’t use previous technic but just common function/command to read/write in a text file in C#.
- You can find the C# file documentation here : File Classe (System.IO) | Microsoft Learn
Hope this help you