Is there a better alternative to process?

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

Im trying to make a shop systems, and one of the problems that faced while implementing this is that I cannot find a better alternative to process listen for the click and what ends up happening is that the script buys until all the money is gone.

Also, each case is a unique button(as in a button node, not a button on the keyboard)
using the lastest version of GoDot (3.2)

Code below:
extends Sprite

var Cash = 200

onready var Shop = get_node(“/root/Node2D/Player/Camera2D/Shop”)

func buy():
while Cash:
match int(Shop.case):
0:
Cash -= 100

			print(Cash)
		1:
			Cash -= 50
			
			print(Cash)
		2:
			Cash -= 5
			
		3:
			Cash -= 5
			print(Cash)
			
		4:
			Cash -= 200
			
		5:
			Cash -= 25
			
		6:
			Cash -= 15
			#Chair
	yield(get_tree(), "idle_frame")

func _process(_delta):
if Input.is_action_pressed(“click”):
buy()
else:
pass

:bust_in_silhouette: Reply From: deaton64

Hi,
Use the signals in the button, either button down or up (whichever one suits you best).
You can attach these to one function and process extra argument (click on advanced when setting up the signal) calls and pass a value. So you don’t need one function for each button, if you have multiple items in your shop and each item is a button.

Thank you so much :smiley:

DoGot | 2020-07-14 23:46