Invalid call to function 'get_var' in base '_File'. Expected 0 arguments.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

I’m writing a load and save singleton and I’m getting this error:

Invalid call to function ‘get_var’ in base ‘_File’. Expected 0 arguments.

Here is the code:

extends Node

# This class loads, save and applies player's game data

var STATE = {
	"PLAYER_NAME": "Player",
	"PLAYER_LEVEL": 1,
	"PLAYER_XP": 0,
	"MAP": "Forest"
	}

var FilePath = "user://game_state.dat"

var Key = "99876827" # encryptation key

func _ready():
	var file = File.new()
	if file.file_exists(FilePath):
		_loadState()
	else:
		_createState()

func _loadState():
	var file = File.new()
	file.open_encrypted_with_pass(FilePath, File.READ, Key)
	
	STATE.PLAYER_NAME = file.get_var("PLAYER_NAME")
	print(STATE.PLAYER_NAME)
	STATE.PLAYER_XP = file.get_var("PLAYER_XP")
	STATE.MAP = file.get_var("MAP")
	file.close()

func _createState():
	var file = File.new()
	file.open_encrypted_with_pass(FilePath, File.WRITE, Key)
	
	file.store_string(STATE.PLAYER_NAME)
	file.store_real(STATE.PLAYER_LEVEL)
	file.store_real(STATE.PLAYER_XP)
	file.store_string(STATE.MAP)
	
	file.close()

func _deleteState():
	var dir = Directory.new()
	var file = File.new()
	if file.file_exists(FilePath):
		dir.remove(FilePath)
		print("State file deleted")
	else:
		print("The state file does not exist")
:bust_in_silhouette: Reply From: p7f

Hi,
That error means that you must not pass any arguments to functin get_var. As the docs says, get_var returns the next Variant value from file. You cannot specify a parameter to tell the function what you want, it will just return the next.