Tell me please
Asked Answered
W

5

0

I'm making a clicker and I need to write the code for the purchase menu.That is, when I click on the button, the cost should be deducted from my balance, and the value added to the click, how do I do this?

Walling answered 9/1 at 9:17 Comment(0)
I
0

It depends on how you implemented your counter above the hippo but a good way is simply to have the button of the market send a signal to the counter telling it to removes 100 watermelons and to execute the code you want.

Infinitesimal answered 9/1 at 12:16 Comment(0)
V
0

Some nodes have signals for certain events. Buttons have events for being pressed, up, down etc. You connect the signals to a function that will be executed when the event is triggered.

Here you'll find an example how to connect a button to a function: https://docs.godotengine.org/en/stable/getting_started/step_by_step/signals.html

Vidal answered 9/1 at 12:20 Comment(0)
V
0

Infinitesimal I guess I missunderstood the question. 😄

Vidal answered 9/1 at 12:29 Comment(0)
W
0

Infinitesimal

My counter is made this way

extends Node2D

var points = 0

func _ready():
	$Label.text = str(points)

func _on_texture_button_pressed():
	points+= 1
	$Label.text = str(points)
Walling answered 9/1 at 15:12 Comment(0)
W
0

I made it so that the cost is deducted from the balance (-50). But I still don't understand how to make the value appear upon click!

extends Node2D

var points = 110

func _ready():
	$Label.text = str(points)

func _on_texture_button_pressed():
	points+= 1
	$Label.text = str(points)



func _on_button_2_pressed():
	points-= 50
	$Label.text = str(points)
Walling answered 10/1 at 8:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.