How to create multiple labels in code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fenisto

Hello. I want to create multiple labels in code, kind of like names for items in an inventory.
I do it kind of like this:

var debug = Label.new()
for i in 10:
	debug.rect_position =  Vector2(50,100) * i
	debug.text = i
	add_child(debug)

But this creates only one label.

:bust_in_silhouette: Reply From: Ertain

There are a couple of ways we might tackle this.

One Label can be assigned for each piece of text:

for i in 10:
    var debug = Label.new()
    debug.rect_position =  Vector2(50,100) * i
    debug.text = i
   add_child(debug)

Or you might be able to use an ItemList.