Automatically fetches player name from username on first open of game
This commit is contained in:
parent
80a9797c0f
commit
50d3c7c895
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue