How to get a variable inside an array?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ismaelgame7
:warning: Old Version Published before Godot 3 was released.
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)
		pass

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?

:bust_in_silhouette: Reply From: Kamil Lewan

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

itemList.add_item(myArray[_NumYouWant][0]),null,true)

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

EDIT:
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
      break
itemList.add_item(myArray[i][0]),null,true)

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

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

ismaelgame7 | 2017-05-21 00:11

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.
Just:
painel.add_item(str(myArray[i][comment1-0]),null,true)
should be enough.
And that pass do nothing too.

Kamil Lewan | 2017-05-21 00:17