How to create saves and loads

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

I have a control script that controls my game, it is a autoload script, i want to know how i can save the data in my control script and load it when continued.
My control script is not attached to any scene or node

:bust_in_silhouette: Reply From: Christoffer Schindel

I’m assuming that you want to store the data locally?
For storage you could use JSON (you can read about it here) or perhaps a local database.

Yeah ive read the docs but i how do i save the data from a script that has no node or scene because the docs talk about groupping and you cant group a stand alone script

Newby | 2018-09-02 22:08

:bust_in_silhouette: Reply From: toragrin

Just use file’s read/write operations at your convenience (full docs or in editor’s Search Help).
In my simplest clicker game, i need to save only top result and using this code:

func save_result():
var settings =
if, File.WRITE) != 0:
	print("Error opening file")

func load_result():
var settings =
if !settings.file_exists(app.SETTINGS_FILE):
	print(" not exist")
	return MAX_VALUE
if, File.READ) != 0:
	print("Error opening file")
	return MAX_VALUE
var top_result_time = settings.get_16()
return top_result_time

where app - autoload singleton not attached to any scene or node.
You can read/write multiple data as JSON (as say Christoffer Schindel), as raw data, bytes, strings, etc, it’s depends on your needs.