This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

hi guys, good day.

how create a StringArray?

Thanks

in Engine by (84 points)

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 pushback) 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(myarray).
I guess, if you fill only with push_back, you can create the array as StringArray([]).

Gokudomatic2: your comment seems to be right, I think you can convert it to an answer.

1 Answer

0 votes
Best answer

It seems the constructor needs an array as parameter, and probably it can't be resized (except for the pushback) 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(myarray).
I guess, if you fill only with push_back, you can create the array as StringArray([]).

by (703 points)
selected by

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

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.

Thank you very much

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 Frequently asked questions and 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 [email protected] with your username.