My question is similar to this
I am using godot game engine and it uses gdscript. I request the moderators to let it stay at least till I get a proper reply. I am at the end of my project this is the only thing I can't accomplish. So, hoping someone will help me here.
I upload three dictionaries to google play as a saved game file when, it gives me json data when I back. Now, I want to convert the integer values back to int, boolean back to bool.
My dictonaries look like this:
Dictionary containing information on levels:
GameDataManager.level_info = 'sand': {
1:{
'unlocked' : true,
'high_score' : 0,
'stars' : 0,
'goals' : {
'score' : 500
},
'level_to_load' : 'res://scenes/levels/sand/1.tscn'
},
2:{
'unlocked' : false,
'high_score' : 0,
'stars' : 0,
'goals' : {
'score' : 2400
},
'level_to_load' : 'res://scenes/levels/sand/2.tscn'
}
},
'ice': {
1:{
'unlocked' : true,
'high_score' : 0,
'stars' : 0,
'goals' : {
'score' : 700
},
'level_to_load' : 'res://scenes/levels/sand/1.tscn'
},
2:{
'unlocked' : false,
'high_score' : 0,
'stars' : 0,
'goals' : {
'score' : 2400
},
'level_to_load' : 'res://scenes/levels/sand/2.tscn'
}
}
There is more but this is a sample.
Booster dictionary looks like this:
BoosterManager.booster_info = 'powers' : {
'plus_bomb' : {
'total' : 0,
},
'hammer' : {
'total' : 0,
},
'swap_pieces' : {
'total' : 0,
},
},
'booster' : {
'color_bomb' : {
'total' : 0,
'set' : false,
},
'adjacent_bomb' : {
'total' : 0,
'set' : false,
},
'column_or_row_bomb' : {
'total' : 0,
'set' : false,
},
}
}
Now when I load this data back I do this for converting the data types back to their original state:
func _on_game_load_success(data):
var game_data: Dictionary = parse_json(data)
GameDataManager.level_info.clear()
BoosterManager.booster_info.clear()
ChipsManager.chips_info.clear()
GameDataManager.level_info = game_data['level_info']
BoosterManager.booster_info = game_data['booster_info']
ChipsManager.chips_info = game_data['chips_info']
for i in GameDataManager.level_info:
var temp_i = GameDataManager.level_info[i]
str(i)
GameDataManager.level_info[i] = temp_i
for j in GameDataManager.level_info[i]:
var temp = GameDataManager.level_info[i][j]
int(j)
GameDataManager.level_info[i][j] = temp
GameDataManager.level_info[i][j]['high_score'] = int(GameDataManager.level_info[i][j]['high_score'])
GameDataManager.level_info[i][j]['stars'] = int(GameDataManager.level_info[i][j]['stars'])
GameDataManager.level_info[i][j]['unlocked'] = bool(GameDataManager.level_info[i][j]['unlocked'])
for k in GameDataManager.level_info[i][j]['goals']:
GameDataManager.level_info[i][j]['goals'][k] = int(GameDataManager.level_info[i][j]['goals'][k])
for i in BoosterManager.booster_info['booster']:
BoosterManager.booster_info['booster'][i]['total'] = int(BoosterManager.booster_info['booster'][i]['total'])
BoosterManager.booster_info['booster'][i]['set'] = bool(BoosterManager.booster_info['booster']['set'])
for i in BoosterManager.booster_info['power']:
BoosterManager.booster_info['power'][i]['total'] = int(BoosterManager.booster_info['booster'][i]['power'])
GameDataManager.save_data()
BoosterManager.save_data()
But when I try to reference it like this GameDataManager.level_info[lvl_type][lvl_num]
where lvl_type is string and lvl_num is int I get a null error. Can anyone help please?