Skip to content

Instantly share code, notes, and snippets.

@BransonGitomeh
Created October 15, 2020 11:32
Show Gist options
  • Save BransonGitomeh/0b048610debcc559931c02d26c3f7e95 to your computer and use it in GitHub Desktop.
Save BransonGitomeh/0b048610debcc559931c02d26c3f7e95 to your computer and use it in GitHub Desktop.
extends Control
var data_file = "user://save"
func _ready():
print("checking if a registration has happened before")
var registrationData = load_from_file()
print("data returned from loading function ", registrationData)
if registrationData:
print("user is already registered as ", registrationData)
$email.text = registrationData.email
# get_tree().change_scene("res://World.tscn")
pass
else:
print("user is not registered")
print("waiting for registration, please enter email")
pass
func save_to_file(data):
var file = File.new()
file.open(data_file, File.WRITE)
file.store_var(data, true)
file.close()
func load_from_file():
var data;
var file = File.new()
if file.file_exists(data_file):
file.open(data_file, File.READ)
data = file.get_var(true)
print("data read from file is ",data)
file.close()
else:
print("file does not exist")
if data:
return data
else:
return null
func _on_save_pressed():
var data = {
"email": $email.text
}
save_to_file(data)
print("saved data to file")
pass # Replace with function body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment