Defining an array of dictionaries (or something kin)

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

Sorry. I’ve looked around here and couldn’t find my answer…

Here’s what I want to do:

Slot = { “Str”: 0, “Dex”: 0, “Int”: 0, “Wis”: 0, “Cha”: 0, “Con”: 0, “Slot”: 0 }

I’m working on an equip setup but I can’t define it in my var statement.

If you could point me to my answer or help me out a little I’d really appreciate it!


:bust_in_silhouette: Reply From: p7f

Have you tried something like this?

var x = []
x.append({ "Str": 0, "Dex": 0, "Int": 0, "Wis": 0, "Cha": 0, "Con": 0, "Slot": 0 })

And you can add sucessive dictionaries with append… So for example, for printing the dictionary saved in the code above you would do:


If you want to print the Str on the dictionary you do:


And so on…

This was EXACTLY what I needed!
I used:
var Slot =
Slot.append({ “Str”: 0, “Dex”: 0, “Int”: 0, “Wis”: 0, “Cha”: 0, “Con”: 0, “Slot”: 0 })

and ran a loop to fill up the slots I needed (8)
I needed to be able to fill and empty the values by variable and this worked!

I was able to get rid of almost a hundred lines of code using this! thanks!

Mystile1369 | 2019-01-29 14:27

You are welcome!

p7f | 2019-01-29 14:30

Hi, sorry I know this is over 2 years old but is it possible to get more than one of the strings or values?

For example: print(x[0][comment2-"Str"]["Dex"][comment2-"Int"])

Is that something I can do? If so how do I do it (I’ve already tried how I’ve done it here and it hasn’t worked for me.

(By the way I am trying to add entries of game titles along with the amount of copies available, the games publisher etc. into an ItemList, if you have any tips on how I can do this that would be amazing).

Thanks in advance!

Lazulily | 2022-08-10 02:09