How do I save a scene as a varible to keep track of what level the player is on?

4.3

Question

I don’t know how to save data to a file i followed a tutorial by DevWorm and he is saving numbers and not scenes and godot keeps saying it cant convert it to a bool so if someone could help me come up with a better system or way of doing this that would be much appreciated

Here is my load and save functions

	var file = FileAccess.open(save_path, FileAccess.WRITE)
	file.store_var(active_level)

func load_data():
	if FileAccess.file_exists(save_path):
		var file = FileAccess.open(save_path, FileAccess.READ)
		active_level = file.get_var(active_level)
	else:
		print("No Save Data Exists")
		active_level = "res://level_1.tscn"

Saving the path or uid to the scene is great, I use it often. What troubles are you runnin into? Can you paste the exact error you get, and it’s line of code?

I can’t access the error at the moment but I will try to recall from memory and if I can’t I will be able to check in about an hour so I think it was cannot convert bool to nir

Ok here’s the error
Invalid type in function ‘get_var’ in base ‘FileAccess’. Cannot convert argument 1 from String to bool.

Ah, yes file.get_var() does not require an argument, it’s single optional argument is a true/false if you want it to load objects, which you do not; you want it to load a single string.

You can fix this by using

active_level = file.get_var(false)

or without an argument using the same false default

active_level = file.get_var()

The argument for get_var does not assign to any variable, that’s what the equals sign is for.

You could also change your get_vars to a more specific file.get_line or file.get_pascal_string if you also chang your stores to file.store_line or file.store_pascal_string