How do I make this more efficient?

Is there a way to make this more efficient?


$UI/CpsButton1/Cost.text = "Cost: %d Mews" % CpsCosts[0]
$UI/CpsButton2/Cost.text = "Cost: %d Mews" % CpsCosts[1]
$UI/CpsButton3/Cost.text = "Cost: %d Mews" % CpsCosts[2]
$UI/CpsButton4/Cost.text = "Cost: %d Mews" % CpsCosts[3]

:laughing:maybe an array and a for loop.

$nodepath is just a shortcut to get_node(nodepath)

so yes, you can do this is a for loop:

	var num_nodes: int = 4
	for i in num_nodes:
		get_node("UI/CpsButton" + str(i+1) + "/Cost").text = "Cost: %d Mews" % CpsCosts[i]
2 Likes