I had no idea that nested dictionaries were a thing! This is very useful!
I'm still a bit confused after attempting to implement this, however.
I currently have 2 dictionaries and they both get their keys from a JSON that looks like this:
{
"Dirt": {
"Durability": 2,
"Breakable": true
},
"Grass": {
"Durability": 2,
"Breakable": true
},
"Stone": {
"Durability": 4,
"Breakable": false
}
}
I'm trying to create the dictionaries like so:
export(Dictionary) onready var durability_map
export(Dictionary) onready var breakability_map
export(Dictionary) onready var merged_map = {durability_map: {}, breakability_map: {}}
And assigning the durability and breakability dictionaries like so:
for tile in get_used_cells():
var tile_id = get_cellv(tile)
var tile_name = tileSet.tile_get_name(tile_id)
durability_map[str(tile)] = int(JsonData.block_data[tile_name]["Durability"])
breakability_map[str(tile)] = bool(JsonData.block_data[tile_name]["Breakable"])
How do I assign the variables to the merged_map?
This code gives me error (Invalid get index '(395, -21)' (on base: 'Dictionary').
merged_map[str(tile)]["Durability"] = int(JsonData.block_data[tile_name]["Durability"])
merged_map[str(tile)]["Breakable"] = bool(JsonData.block_data[tile_name]["Breakable"])
I'd want the merged_map dictionary to look like:
merged_map = ["0,0" : {"Durability:" 2, "Breakability": true}, "0,1": {"Durability:" 4, "Breakability": false}
for example.
How exactly do I need to declare the dictionary in order to achieve this?
I saw each key had 3 values in your example. Did you make a dictionary of 3 dictionaries?
Sorry for being slow, it's my first time working with dictionaries in Python/GDscript, let alone nested dictionaries! ^^'