Godot Version
4.3 Stable
Question
So I followed this tutorial for save and load states
here: https://www.youtube.com/watch?v=lXO5Jt957BA
and I was following along with my own script, and I keep getting this error.
Parser Error: Invalid argument for "get_var()" function: argument 1 should be "bool" but is "String".
Heres the code if that helps
var StringVar : String = "DefaultString"
const FileString = "res://SaveFilePath.save"
func save():
var File = FileAccess.open(FileString, FileAccess.WRITE)
File.store_var(StringVar)
File.close()
func Load():
if FileAccess.file_exists(FileString):
var File = FileAccess.open(FileString, FileAccess.READ)
StringVar = File.get_var(StringVar)
File.close()
else:print("Theres No Data Here")
How do I fix this?
seems like you passed an argument that is a string inside the get_var() fuction.
Something like this
File.get_var(someString)
It should be removed.
Maybe check your entire script for that or maybe paste it here
Hello Me Again I forgot some parts of the code so I edited it to show what I was dealing with
func Load():
if FileAccess.file_exists(FileString):
var File = FileAccess.open(FileString, FileAccess.READ)
# Right Below this note
StringVar = File.get_var(StringVar)
# Right Above This Note
File.close()
else:print("Theres No Data Here")
This is exactly where I get this error! from what I gather the get_var() function is supposed to retrieve a variable from the save file, however the function only takes a bool for some other reason. In the tutorial he used multiple integers with the get_var() function like this.
var variable1 = 0
func load():
FileAccess.file_exist(save_path):
var File = FileAccess.open(save_path, FileAccess.READ)
variable1 = File.get_var(variable1)
How can i retrieve the string i saved in the save file?
It should be
StringVar = File.get_var()
Same here
variable1 = File.get_var()
Godot has a built-in function called load
so you should rename your function to something else
2 Likes
Thanks for the help! I realized what my issue was so ill log it here for future reference.
I was not setting a value to the string variable!
Therefore I was just saving an empty string, thinking it was broken.
Thanks again for the help!
1 Like