Topic was automatically imported from the old Question2Answer platform.
Asked By
Aquiles
Old Version
Published before Godot 3 was released.
hi guys, good day.
how create a StringArray?
Thanks
Do you mean the class StringArray? Or a mere array of String?
Did you try the usual way? It seems the constructor needs an array as parameter, and probably it can’t be resized (except for the push_back) because it’ seems to be a C array. If it’s true, then you have to build first an array of strings, and then give it to the constructor StringArray(my_array).
I guess, if you fill only with push_back, you can create the array as StringArray().
Gokudomatic2 | 2016-04-14 07:21
Gokudomatic2: your comment seems to be right, I think you can convert it to an answer.
It seems the constructor needs an array as parameter, and probably it can’t be resized (except for the push_back) because it’ seems to be a C array. If it’s true, then you have to build first an array of strings, and then give it to the constructor StringArray(my_array).
I guess, if you fill only with push_back, you can create the array as StringArray().
Gokudomatic2 thanks for answering my question.
how it works in practice or write what you tell me.?
I have an array that looks like this:
var infoitem = [ ["Text", "Text"],["Text", "Text"],["Text", "Text"],["Text", "Text"]]
Aquiles | 2016-04-14 16:24
I just tested this code, and it works:
var t1=["1","2","3"]
var sa=StringArray(t1)
print(sa)
It looks like StringArray() is also valid and creates an empty array.
With your double dimensional array, I think you have to iterate:
var l=StringArray()
for x in infoitem:
for y in x:
l.push_back(y)
or if you want to keep the 2 dimensions, you must do an array of StringArray.