0 votes

Hello, can anyone tell me how to use has() in the array?
I'm having trouble checking if there is an item in the array :/

var myArray = [["notebook",0],["book",1],["phone",2]]
var listID = 1
    if myArray.has(myArray[listID]):
        myArray.remove(listID)
    pass

In this example I'm trying to check if an index 1 in array
only that Godot points this error >> Invalid get index '1' (on base: 'Array').

Can someone help me please!?

asked May 21, 2017 in Engine by ismaelgame7 (143 points)
edited May 22, 2017 by ismaelgame7

3 Answers

+1 vote
Best answer

My friend helped me here.
So my code looks like this:

if (listID < imagens.size()):
   myArray.remove(listID) 
  pass
answered May 22, 2017 by ismaelgame7 (143 points)
0 votes

Do you want get 2nd var in that small arrays e.g. ["book",1]?

for i in myArray:
   if i[1] = listID
      myArray.remove[i]

should work.
pass is not necessary. It does nothing.
PS. Please write more exactly WHAT do you want to get.
PS1. Please write line of code where you got error (3,4?)

answered May 21, 2017 by Kamil Lewan (183 points)
0 votes

I want to get an index from my array and remove it
Type: var listID = 1
Var myArray = [["notebook", 0], [Delete], ["phone", 2]]
The error is just in this line >> if myArray.has(myArray[listID])
I know that the pass does nothing, I just use it to make it cute
It's hard to express yourself on the internet, I try but I'm not very good at it. kkkkkk

answered May 22, 2017 by ismaelgame7 (143 points)
edited May 22, 2017 by ismaelgame7
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 How to use this Q&A? before posting your first questions.