Issue when trying to append to a list

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

Hi all,

I’m trying to do the following:

func setup_board():
	for x in range(5):
	    board.append(['O']*5)

… but I get this error:

Invalid operands 'Array' and 'int' in operator '*'.

Can anyone point to what’s going wrong here? I understnad it’s saying something like I can’t perform a multiplication on an Array but I’m doing a python tutorial and this works in Python. In that case, how would I do it in GDScript? I should probably note that I’ll be replacing ‘O’ with a sprite in time. This is just a quick prototype.

BTW, in Python this is the output and what I’m basically trying to achieve:

['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']
['O', 'O', 'O', 'O', 'O']

Any advice greatly appreciated.

:bust_in_silhouette: Reply From: ludosar

Hi, this issue has already been discussed:
https://forum.godotengine.org/5122/how-do-i-create-a-2d-array

Thank you, much appreciated and sorry I didn’t see that one earlier.

Robster | 2016-09-01 01:04