func _on_pressed() -> void:
var bought = self.text
for i in Gm.storedfood:
if Gm.stored[i][0] == bought:
Gm.stored[i][1] += 1
else:
Gm.stored.append[bought][1]

using this code to try and edit an array in order to add a purchased item to it or not however it returns the error
Invalid access to property or key '["name", "amount"]' on a base object of type 'Array'
not sure why

    its erroring at the start of the if rather than at the end

      Thundershade maybe then you haven't added the correct indents as im looking at the code you posted, its not properly indendent

      Other than that there are many more questions about your situation that you havent provided..

      what is the storefood type?
      maybe you need to make it dict?
      the error itself is telling you that there is no key in arrays

      using a dict seemed to be what i was looking to do thanks

      • Edited

      Thundershade When iterating over an array using a for..in loop, the iterator variable will contain actual elements, not their indexes.

      the iterator variable will contain actual elements, not their indexes.

      Detailed example:

      var a: Array[int] = [15, -4, 88]
      
      for i in a:
          print(i) # prints 15, -4, 88
      
      for i in range(a.size()):
          print(i) # prints 0, 1, 2
          print(a[i]) # prints 15, -4, 88