cashier display?

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

so uh, i tried to make a scanner-like item for a game, which when a certain item or ‘goods’ overlap, will display certain ‘price’ value.

so my node looks like this :

then i add code:

basically displaying whatever ‘price’ value i put there.

my question is, how do i set the label, so it will show the total price ?
i tried to put a an ‘area_entered’ signal in the scanner and the goods, but they only display initial value of each item.

:bust_in_silhouette: Reply From: Thomas Karcher
  1. Create a dictionary variable for the goods currently overlapping with the cashier.
  2. Update this dictionary whenever a good is added or removed.
  3. Sum up all goods in the dictionary to get the total price
# add items in the "entered" method
# remove items in the "exited" method
var items : Dictionary = {
	'Milk': 2.50,
	'Eggs': 3.99

var total_price : float

func update_total_price():
	total_price = 0
	var price : float
	for price in items.values():
		total_price += price
	print (total_price)