Why my code is not working&

Godot Version 4.2.2

Why my code is not working?

Code:

extends Node

var save_path = “user://Save&Load./Save.save”

var NickName = Nickname.nickname

func _save():
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_var(Nickname.name)

func _load():
var file = FileAccess.open(save_path, FileAccess.READ)
NickName = file.get_var(save_path)

func _ready():
if FileAccess.file_exists(save_path):
if NickName != “Dev”:
get_tree().change_scene_to_file(“res://Menuuu/Menu.tscn”)

func _on_button_pressed():
_save()
get_tree().change_scene_to_file(“res://Menuuu/Menu”)

file.get_var(save_path)
this should be file.get_var() as get_var does not require a parameter to get the value.

Oshibka2

So opening the file fails

Change to

user://save_load/save.save

& Ampersands shouldn’t be used in file names. Also capital letters are not utilized in all operating systems and should be avoided in filenames.

Thanks, but this is not working

Oshibka

I think you have a syntax error. But it’s not really clear. Please correct the syntax, or share a picture of the path code.

It should look like this.

Line 11 doesn’t work, I checked through print

Unfortunately I don’t have line numbers.

file.store_var(Nickname.name)

It seems like fileaccess cannot create directories on its own.

func _create_folder():
	DirAccess.make_dir_recursive(save_path.get_base_dir())

func _save():
	if not DirAccess.dir_exists_absolute(save_path.get_base_dir()):
		_create_folder()
    ...

In order to understand why file might be null you need to access the error code.

var file = FileAccess.open(...)
if file == null:
  print(FileAccess.get_error())

The list of errors

Yo, could you help me?? I have a small problem… Only experienced godot users... I cant figure this out... I need professional help

1 Like