0 votes

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

Invalid call to function 'getvar' 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):

func _loadState():
    var file = File.new()
    file.open_encrypted_with_pass(FilePath, File.READ, Key)

    STATE.PLAYER_NAME = file.get_var("PLAYER_NAME")
    STATE.PLAYER_XP = file.get_var("PLAYER_XP")
    STATE.MAP = file.get_var("MAP")

func _createState():
    var file = File.new()
    file.open_encrypted_with_pass(FilePath, File.WRITE, Key)



func _deleteState():
    var dir = Directory.new()
    var file = File.new()
    if file.file_exists(FilePath):
        print("State file deleted")
        print("The state file does not exist")
in Engine by (695 points)

1 Answer

0 votes

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.

by (3,505 points)
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 Frequently asked questions and 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 [email protected] with your username.