Thanks for the info. Here’s a some more information on my nested dictionaries.
In this game, there are eight different game profiles that can be randomly selected. Each one has the eight chests in it which may or may not require a key to open and may contain other items. This dictionaries, as stated before, are setup in a global script.
var chest1 = {}
var chest2 = {}
var chest3 = {}
var chest4 = {}
var chest5 = {}
var chest6 = {}
var chest7 = {}
var chest8 = {}
var chest_map = {}
Each profile is hard-coded with values for eight chests…
var number_of_game_profiles: int = 8
var sel = 0
func load_game_profile() -> void:
#randomly select which chest map is to be used
sel = randi_range(0,number_of_game_profiles)
#print("chest map selected: ", sel)
match sel:
0:
chest1["contains"] = "C3"
chest1["key_needed"] = ""
chest2["contains"] = "G3"
chest2["key_needed"] = "K1"
chest3["contains"] = "FA"
chest3["key_needed"] = "K1"
....etc.
…and then all the chests are loaded into the chest_map dictionary.
chest_map = {1:chest1, 2:chest2, 3:chest3, 4:chest4, 5:chest5, 6:chest6, 7:chest7, 8:chest8}
As all the dictionaries are hand populated during game design, there is no chance of having a blank key or key error.
I do like your suggestion to use ‘get’ as that allows me to simplify my logic for chests that do not require a key.
chest_map.get(2, {}).get("key_needed", false)
In note #4, you state that “maybe the dictionary hasn’t been filled yet”. Won’t the global script run before any other scripts? Remember, the chest_map is readable in the main scene. If my understanding is wrong, how do I ensure that the global script finishes processing before the rest of the scripts start?
And once again, thanks for your insights.