Automatically fetches player name from username on first open of game

This commit is contained in:
Paul Black 2023-03-06 18:43:31 -07:00
parent 80a9797c0f
commit 50d3c7c895

View file

@ -16,6 +16,14 @@ func _ready():
func check_data(): # Makes sure the save file exists
var file = FileAccess.open(SETTINGS_FILE, FileAccess.READ) #If we write, it writes an empty file over our existing one
if not file: # If there's no file, let's create one with FileAccess.WRITE
if OS.has_environment("USERNAME"):
print("env has USERNAME var")
settings_template[1] = OS.get_environment("USERNAME")
elif OS.has_environment("USER"):
print("env has USER var")
settings_template["playername"] = OS.get_environment("USER")
else:
print("env has no known user var")
print("file does not exist, let's create one!")
var file2 = FileAccess.open(SETTINGS_FILE, FileAccess.WRITE)
file2.store_line(JSON.stringify(settings_template)) # Writes settings_template to our file SETTINGS_FILE