0 votes
var save = 0                                                                                                                                           func save(save):
    var file = File.new()
    file.open("user://savegame.save", File.WRITE)
    file.store_var(save)
    file.close()

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

    return 

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)

in Engine by (103 points)

1 Answer

0 votes

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(save)
    save = 1
    print(save)
    load_()
    print(save)

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.

by (2,832 points)

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

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!!

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.

https://www.wikihow.com/Open-Applications-With-Root-Privileges-on-a-Mac

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.