Load/Save not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ManiCus
var save = 0                                                                                                                                           func save(save):
    var file = File.new()
    file.open("user://savegame.save", File.WRITE)

func load_():
    var file = File.new()
    file.open("user://savegame.save", File.READ)
    save = file.get_var(save)


The code is working and saving the “var” when running the game from godot, but when i export the project and i run it, the “var” wont be saved or loaded correctly
(Exporting for mac)

:bust_in_silhouette: Reply From: timothybrentwood

I copied your functions and did this in my own editor and it worked as anticipated, prints 1 then 0:

var save = 0    
func _ready() -> void:
	save = 1

Try changing user://savegame.save to res://savegame.save in both functions and see if that gives you any results. If that works you have a permissions issue in the directory that user:// points to. If it doesn’t work, i think you have a permissions issue overall.

Ok, i changed from user:// to res:// and now my var is “null” when I run it in Godot and when i export it too

ManiCus | 2021-05-02 15:27

never mind, i solved it, i don’t know how, but i did it. I changed back to user:// and some how it worked

Thanks for helping however!!

ManiCus | 2021-05-02 15:38

I think it’s a permissions issue. Try running the executable equivalent produced by Godot after the export process as an administrator or root user. If I recall correctly you usually have to type in a password before a program is ran as an administrator in Mac OS.

3 Ways to Open Applications With Root Privileges on a Mac

timothybrentwood | 2021-05-02 16:00