Files
berry-dash-godot-remake/Scripts/BazookaManager.cs
T
Puppet 330258f987 Made it save your high score whenever you hit a poison berry
I'm gonna add a pause menu later and whenever you go back the main menu
with that it will save your high score there too.
2025-10-12 17:08:59 -07:00

25 lines
826 B
C#

using Godot;
public partial class BazookaManager : Node {
public static string HighScore = "0";
public static string Read(string saveKey, string defaultValue) {
string path = "user://" + saveKey + ".txt";
if (!FileAccess.FileExists(path)) {
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(defaultValue);
return defaultValue;
} else {
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
return file.GetAsText();
}
}
public static void Write(string saveKey, string value) {
string path = "user://" + saveKey + ".txt";
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Write);
file.StoreString(value);
file.Flush();
}
}