Set the value of a 2D array [Solved]

Godot Version

4.2.2

Question

Just a simple syntax question I’m having trouble finding a simple answer to.

I have:

var myarray = [
	{ "B_1": 5},
	{ "P_1": 5},
	{ "G_1": 5},
]

I want to change “B_1” from 5 to 4. Like:

myarray["B_1"] = 4

Or such. And I just don’t know/can’t find the syntax to accomplish that.

In this example you could use a dictionary directly.

var myarray = {
	 "B_1": 5,
	 "P_1": 5,
	 "G_1": 5,
}

myarray["B_1"] = 4

Otherwise keeping with the Array[Dictionary] type you need to index which element, then pick a key

myarray[0]["B_1"] = 4
1 Like

Yep! That’s exactly what I needed. Thank you muchly!

1 Like