thomas
January 20, 2024, 4:36pm
1
Godot Version
4.2.1
Question
Is it possible to edit keys or values of an array nested dictionary?
When doing something like this:
var dict = {"key":"value"}
var arr = [1,2,dict]
func _ready():
arr[2]["new_key"] = "new_value"
This is the output: [1, 2, { “key”: “value”, “new_key”: “new_value” }]
You get an extra dictionary instead of edit the old one [2].
Btw. you can create a dict inside of an array without giving it a name, how is it possible?
That output shows only 1 dictionary with two entries.
arr[0] = 1
arr[1] = 2
arr[2] = {
“key”: “value”,
“new_key”: “new_value”
}
If you wanted to change the first value then:
arr[2]["key"] = "new_value"
create a dict inside of an array without giving it a name
I don’t understand this question.
1 Like
thomas
January 20, 2024, 5:31pm
3
Is it also possible to edit the key and keep the value?
I meant, you can create a dict without a dict name like that:
array[1,2, {“key”: “value”}]
Now you can reference this dict by the array it is in but not by its name. I was just wondering how this work
The only way to rename the key is to make a new key:value pair and delete the old one.
Sure you can create a dictionary in an array without create a variable for it first:
var arr:Array = [1,2, {Key:Value, Key2:Value2}]
print(arr)
This prints
[1, 2, { "Key": "Value", "Key2": "Value2" }]
1 Like
system
Closed
February 19, 2024, 6:00pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.