+1 vote

So, i have an array for a scoreboard, which holds a number of arrays for rank, name and score values and i want to print them into labels on a grid container with a for loop.
I've tried something like this:

for entry in board:
      var rank = Label.new()
      var score = Label.new()
      var name = Label.new()

But i always get an 'Invalid get index '1' (on base: 'Array').' message. Index[0] works fine, but everything above it not.
I've also tried "for i in range(0, entry.size())" in a new for loop, but i still get the same error.

To just print the strings i could do
for i in entry: var lable = Label.new() table.add_child(label) lable.set_text(str(i))
But i want to access the indices.

in Engine by (45 points)

1 Answer

+2 votes
Best answer

Is this what you want?

var board = [[50, 10, "John"], [60, 5, "Ray"]]

for entry in range(board.size()):
by (598 points)
selected by

That's what i want, but it still does not work. I get the same error message.

OK, i've tried it again with a self written array and it worked. It seems there's something wrong with my original array. I get the array from a long string, which i convert with

global.board = Array(text.split(";"))

and than again in a for loop like this:

for i in global.board:
        var boardSub = Array(i.split(":"))

But your method definitely works. Thank you!

you're welcome.

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.