0 votes
var item = "notebook"
var myArray = [[item,0],[item,1],[item,2],[item,3]]
    for i in range(myArray.size()):
        i = itemList.add_item(str(myArray[i].find_last(item)),null,true)

I'm trying to put a name that is in my variable in my itemList, but I just can not get.
Can someone help me please?

in Engine by (147 points)

1 Answer

+1 vote

Not sure if i understand you.
You want get item (string) from that small arrays?
Then you must know which one you want (_NumYouWant)

var item = "notebook"
var myArray = [[item,0],[item,1],[item,2],[item,3]]


I don't know why you used find_last().

Ok, probably I misunderstand you. Could you explain exactly what you want get and where set it? Something like this?

var item = "notebook"
var myArray = [[item,0],[item,1],[item,2],[item,3]]
# To check it found item
var _last = -1
# Simulate find_last()
for i in range(myArray.get_size(),0,-1):
   if myArray[i][0] == item:
      _last = i
by (186 points)
edited by

I wanted to get the variable (String) inside my array.
I managed to see your code before you edit it, Kamil Lewan .
So I understood that I just had to do this:

var item = "notebook"
var myArray = [["book",0],["phone",1],["pencil",2],[item,3]]
    for i in range(myArray.size()):
        i = painel.add_item(str(myArray[i][0]),null,true)

Now i know that find_last () only returns me an int. kkkk
Thank you!!

No problem. Still, don't know why you use:
i = foo()
i is iterator in range(myArray.size()); its integer, so setting something here is purposeless I think. It'll be deleted after iteration.
should be enough.
And that pass do nothing too.

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.