blob: 02989b1968ca63022703cf4838ecfc801afd6517 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
extends Node
var server_url = ""
var error_message = ""
var character = 1
var username = "Giovanni"
func _ready():
load_profile()
func save_profile():
print("Save profile")
var f = FileAccess.open("user://profile", FileAccess.WRITE)
f.store_line(JSON.stringify({
"username": username,
"character": character
}))
func load_profile():
# TOCTOU here. Godot docs says its fine.
if not FileAccess.file_exists("user://profile"):
print("Skip profile load")
return
print("Load profile")
var f = FileAccess.open("user://profile", FileAccess.READ)
var ob = JSON.parse_string(f.get_line())
username = ob["username"]
character = ob["character"]
|