Change multiple label text in a loop (change variable type into a label in script?)

Godot Version

V4.7

Question

I want to automatize this with a loop for:

histoire_actu = banque_histoire_tempo.pop_front()
texte_carte_1.text = histoire_actu[numero_tirage]
histoire_actu = banque_histoire_tempo.pop_front()
texte_carte_2.text = histoire_actu[numero_tirage]
histoire_actu = banque_histoire_tempo.pop_front()
texte_carte_3.text = histoire_actu[numero_tirage]

I made this but it’s not working and it say “Invalid assignment of property or key ‘text’ with value of type ‘String’ on a base object of type ‘String’.”. I think it’s because my value “carte_actu” is a var and not a label, but how can I do it? It must have a way?

Sorry, I’m new and it’s maybe simple (or not possible) but I don’t know how to search for this issue.

Thanks you!!

("$"+carte_actu) doesn’t fetch a node, it just joins two strings. To access a node from a variable NodePath, use get_node(carte_actu). If you want to access one of your texte_carte_ export variables, you could use either get(carte_actu) or self[carte_actu].

Though it would be even easier to just put all the labels in one array, and iterate over the array. Then you wouldn’t have to deal with NodePath/PropertyPath strings at all.

@export var texte_carte: Array[Label]
var histoire_actu

# ---
for i in 3:
	histoire_actu = banque_histoire_tempo.pop_front()
	texte_carte[i] = histoire_actu[numero_tirage]

Or simpler without popping:

for i in 3:
	texte_carte[i] = banque_histoire_tempo[i][numero_tirage]