Godot Version
v4.4.1 stable
Question
Super noob question, but what’s the best way to add to a Dictionary in GDScript? I want something like the “append” function of Arrays. I have a Dictionary of Dictionaries and I want to add to it in other parts of the script, here’s my code:
This is the initial setup of “test_data” the parent Dictionary:
# Save battle data
func save_battle_data() -> void:
test_data = {
0: {
"FileName": Data.generate_file_name(),
"Rounds": round_limit,
},
1: {
"ChampionID": 0,
"Name": "Alena",
"Damage": 150
}
}
Here’s where I’m trying to add to the Dictionary using the “get_or_add“ function:
BATTLE_STATE.POST_BATTLING_PHASE:
turn_timer.stop()
end_battle()
save_battle_data()
test_data.get_or_add({
2: {
"ChampionID": 1,
"Name": "Annabel",
"Damage": 100
}
})
Data.save_training_dummy_battle(test_data)
But the “get_or_add” function comes out like this:
I couldn’t find much help on Google, does anyone know a good way to do this?
