This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

This is my first game . I am making a save system and getting an error as follows:
Invalid get index 'unlockedlevel' (on base: 'Dictionary') . Searched for answers online and did not got any . Please help me


var coins = 0
var levels = []
var unlockedlevel = 1


#save game
func save_game():
    var save_file ="user://" , File.WRITE)
    var data = {

#load game
func load_game():
    var save_file =
    if !save_file.file_exists("user://"):
        return"user://" , File.READ)
    var data = save_file.get_var()
    coins = data["coins"]
    unlockedlevel = data["unlockedlevel"] #error
Godot version 3.3.4
in Engine by (12 points)
edited by

If the words need to be scrunched together, I would suggest using "camel case" for key names, e.g. UnlockedLevel. That makes it a bit easier to read the name. I would also suggest checking for the key name in the dictionary:

if data.has("UnlockedLevel"):
    unlockedlevel = data["UnlockedLevel"]

That way, the game can be programmed to react to data that isn't there. If the data isn't being saved to a file, or the file doesn't have the data, then that issue will have to be addressed.

Please log in or register to answer this question.

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.