How to add a cap to my clicker game?

Godot Version

4

Question’ Ask your question here! Try to give as many details as possible`

I’m trying to have the amount of times you can click on the apple and get a point for it to be limited to 5 and then have it not do anything anymore. don’t know where to start. its all working so far, but i just need to add this.


var money = 0
var apple = 0
var bread = 0
var milk = 0
var knife = 0
var pepperspray = 0

func _process(_delta: float) -> void:
	$money_label.text = "Money: " + str(money)
	$Label.text = "Apples: " + str(apple)
	$Label2.text = "Bread: " + str(bread)
	$Label3.text = "Milk: " + str(milk)
	$Label4.text = "Pocket Knife (optional): " + str(knife)
	$Label5.text = "Pepper Spray (optional): " + str(pepperspray)
	
	
func _on_wallet_pressed() -> void:
	money += 1

func _on_apple_pressed() -> void:
	if money >= 5:
		money -= 5
		apple += 1

It should be as simple as changing your apple pressed function to :
if money >= 5 and apple < 5:

So once apple reaches 5, it wont work anymore. Assuming apple is the variable you use to count how many clicks there have been

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.