0 votes

Hi this is a project in my final year of University.
I am trying to load a JSON file that when the level is unlocked it is then playable but it doesn't seem to work although the code runs fine.

if attribute == "unlocked":
    if data[node_path][attribute] == true:
        print("DLI: ", GameDataManager.level_info[levelButton.Get_Level()])
        print("Levels: ",levels[levels.count(levels)].Get_Enabled())

That is from the save script and in the level button script (which should unlock the level this is the code:

func Set_Level_Enabled(level_enabled):
enabled = level_enabled
enabled = GameDataManager.level_info[Get_Level()]["unlocked"]
GameDataManager.level_info[Get_Level()] = {
    "unlocked" : true,
    "keys_collected" : HUD.Get_KeyCount(),
    "flies_collected" : HUD.Get_FlyCount()
print("LVL: " , Get_Level())
return enabled

If you want to see the other functions then drop me a message and I can show it to you
I have a deadline very soon, please help

in Engine by (13 points)

I don't know whether this is due to a bug in the engine (there have been some problems with saving Godot objects in JSON). Have you tried assigning true as a string in the dictionary? When you need to check for a true statement, also look for the string. For example, your dictionary could look like this:

GameDataManager.level_info[Get_Level()] = {
    "unlocked" : "true", # This has been changed to a string.
    "keys_collected" : HUD.Get_KeyCount(),
    "flies_collected" : HUD.Get_FlyCount()

Then change your code to this:

if attribute == "unlocked":
    if data[node_path][attribute] == "true": # The check has been changed, too.

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 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 webmaster@godotengine.org with your username.