Cannot Unlock my level when loading from a file PLEASE HELP

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

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

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.

Ertain | 2020-04-24 19:56