My second function doesn't run?

Godot Version

I’m on Godot version 4.72 or latest release.

Question

I am not sure why my second line of code doesn’t run, there is also zero errors or warnings I think it just didn’t even execute. I want the code to have a button where if you click it will create a clicker that gives you one cookie every second like the clicker from cookie clicker as you can see.

extends Button

var price_of_clicker = 10
var clicker = 1
var amount_of_clicker = 0

func _pressed():
	if Global.Cookie >= price_of_clicker:
		Global.Cookie -= price_of_clicker
		price_of_clicker *= 1.5
		amount_of_clicker += 1
	else:
		print("You dont have enough money to buy a clicker")
		
func _ready(): 
	if amount_of_clicker > 0:
		print("This went through")
		while true:
			await get_tree().create_timer(1).timeout
			Global.Cookie = amount_of_clicker * clicker

Be more specific. The second line of code is var price_of_clicker = 10

Why do you think it doesn’t run? What does it show? What are you expecting it to show?

I think it doesn’t run because it might be not running because there is only else condition the reason i’m confused is because I need to add a _ready function or it will only generate after I click again. It shows only the first function with no errors or warnings. Im expecting it show “This went through” to confirm it works.

In ready, you check if amount_of_clicker is greater than 0. It is not. It is equal to 0. You need to change the first line of ready to “>=” instead of “>”.

Also, you throw in some weird while loop that looks like a complete mess to me. If i were you i would replace it with something else. It will probably crash your game if you would only reach it.

You are completely right about > instead of >= I always forget.. But also the while loop works fine as a passive income source should be infinite but it also has a timer to delay it, although I think you are write because the delay is after the while loop which might crash my game.

You were right… I put > instead of >=