I'm tryin to code a save system for my project, and I wanted it to be accessible from any code anywhere so I made a script "SaveGame.gd" and in project settings made it an auto load called "Saver". The code in it goes like this
class_name SaveGame
extends Resource
const save_base_path := "user://save.save"
var lastSave
func save_to_file():
var save_dict = {
"lastTime" : GlobalResources.lastTime
}
var save_game = FileAccess.open("user://save.save", FileAccess.WRITE)
save_game.store_var(save_dict)
print("saved")
func load_save():
var save_game = FileAccess.open("user://save.save", FileAccess.READ)
var data = save_game.get_var()
lastSave = data.lastTime
print("loaded")
it fetches data from another autoload to create a test savefile, then in my main scene I have a script (main.gd) that when i press a button calls those functions, the part that does that goes like this:
func _process(delta):
if Input.is_action_pressed("ui_text_backspace"):
Saver.save_to_file()
if Input.is_action_pressed("ui_up"):
Saver.load_save()
but whenever I press the buttons that call those functions I get that dreaded Invalid call. Nonexistant function 'save_to_file' in base 'Nil'. . And so I made a test, moved the said save and load functions to main.gd and they JUST WORKED. So I am baffled, read a lot of stuff on the web already and I'm beginning to lose my mind! My project depends on my capacity to learn to create this save system, but I just cant seem to make it work as an autoload (or singleton as some say). There are no misspellings as I thorougly verified the name of the autoload that just have 5 letters and the editor even autocompletes the functions for me after i type in the "."
Thanks in advance to anyone that hears my plea, I'll give any extra info necessary