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.
+1 vote

Hello,

I am looking for a file to fill 'array' type 'string'
the declaration of the 'string array':

var test: PoolStringArray = []

and then..
var i: int
i = 1
...
test [i] = file.get_line ()
..

But I have this message; invalid set index '1' (on basis: 'PoolStringArray') with value of type 'String'
??

in Engine by (27 points)

1 Answer

0 votes

You get this error because you didn't resize the array. Accessing indexes without giving proper size to the array results in invalid index.

For your use case, I would suggest you use append, which increases size by 1 and adds the line at the end of the array:

test.append(file.get_line())

In case you know in advance how many lines there is:

test.resize(line_count)
...
test[i] = file.get_line()

Another thing to note: array indexes start from 0, not 1.

by (29,510 points)

okay, and can we define the dimension of 'Array' to the declaration of the variable?

thank you
ps; original your audio story on your site.

You can't declare the size of the array at the same line of creation of the array, it needs a second line:

var lines = []
lines.resize(42)

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.