0 votes

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

Here's what I want to do:

Slot[x] = { "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!


in Engine by (34 points)

1 Answer

+1 vote
Best answer

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..

by (3,505 points)
selected by

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!

You are welcome!

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]["Str"]["Dex"]["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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.