0 votes

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.isactionpressed("click"):
buy()
else:
pass

in Engine by (24 points)

1 Answer

+1 vote

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.

by (1,483 points)

Thank you so much :D

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories