I'm a Vue developer - How do you make an array of objects in GDScripts?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SamuelMb

So, I’m aware that the term “object” might have a different meaning in gdscript then it has in web development (vue/javascript) where I usually work. Which is why I have been having a hard time framing the question appropriately. I think the best way to explain what I am asking would just be to show you want I want to do. This is what I would want:

array = [
{name: Jack, age: 21},
{name: Jill, age: 24},
{name: Trump, age: 7}

return array[0] = {jack, 21}

As I understand it arrays in gdscript can’t do this? Or can they and I just don’t know how? And if they can’t is there something else that I can use to do this instead of arrays?

Edit: Actually never mind. I figured it out. I just forgot to put the labels in quotes, lol. This is how you do it:

array.append({“name”: “Jack”, “age”: 21})

Note that what you’re doing here specifically is making an array of dictionaries.

kidscancode | 2019-12-21 00:37

You don’t need quotes on identifiers if you assign with =

var array = [
		name = "Jack",
		age = 21

hammeron | 2019-12-21 13:05

Yes, but this only works for string keys, while dictionaries can use many data types for keys. I don’t recommend jumping between Python dictionary syntax and Lua table syntax - it only leads to confusion.

kidscancode | 2019-12-21 15:21

Thank’s for that clarification by the way. Actually really helps to know how to frame things when you are googling for answers to problems.

SamuelMb | 2019-12-21 16:41