If you don't change the script you have to attach it to the parent-node of a Label-node called "PriceLabel" (case-sensitive!) - the dollar-sign is just a shorthand symbol for get_node
. If you want to attach it to the Label-node itself, it would be:
extends Label
var price = 1337
func update_price(price : float) -> void:
text = "%.2f" % price
It all depends on what you're trying to do. As long as all paths are correct the script will work, no matter where it's located. The text
is a property of your Label, so you need to get the label first. The price
is a variable defined in a script, so you need to get the node this script is attached to first. How exactly you get those two nodes depends to which node your script for updating the price is located and how your trees looks.