How to check a dictionary value to see if it is equal to something GDSCRIPT

Viewed 53

I have some code that determines if the player has bought something or not in the store. I want to give that player the item if any of the values == true

var store = {
    'bought' : [false, false, false, false, false, false],
    'purchased': 0,
}

i was trying something like if (store[bought[1]]) == true but i suck at coding so it doesnt work

1 Answers

So, you have a dictionary named store. And it has a 'bought' key that you can read, like this:

var bought = store['bought']

Or like this:

var bought = store.bought

And that key is associated with an array, that you can index, like this:

var bought = store['bought']
var item = bought[0]

Or like this:

var bought = store.bought
var item = bought[0]

Or, if you don't want to take bought in a separate variable, you should be able to access it like this:

var item = store['bought'][0]

Or like this:

var item = store.bought[0]
Related