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?
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.
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
Infinitesimal I guess I missunderstood the question. 😄
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)
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)
© 2022 - 2024 — McMap. All rights reserved.