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]):

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!?

in Engine by (150 points)
edited by

4 Answers

0 votes
Best answer

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

if (listID < imagens.size()):
by (150 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

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?)

by (186 points)

Use == in an if statement.

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

by (150 points)
edited by
+2 votes
var my_array = ["one", "two", "three", "four"]

if my_Array.has("three"):
    # do stuff


if "three" in my_array:
    # do stuff


by (249 points)
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.
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 webmaster@godotengine.org with your username.