Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | arbitrarybarry |
Hi, I am brand new to Godot and still obviously have much to learn about GDscript.
I am trying to make an idle clicker game, and I want to disable a button node if the player does not have enough money (grass in this case) to cover the cost of the optimize button.
So far the player can click on a “Get Grass” button which increases the grass value by 1 each click. The optimize button increases the amount of grass earned in a single click. I entered the following code:
extends Panel
export var grass = 0
export var optimize = 1
export onready var timer = get_node(“Timer”)
export var optimize_cost = 5
func _ready():
if grass < optimize_cost:
get_node ("Optimize").disabled = true
elif grass >= optimize_cost:
get_node ("Optimize").disabled = false
UpdateUI()
But when I run the game the Optimize button stays enabled even though the player has less grass than optimize_cost.
Any help or even a recommendation of a different method would be much appreciated, Thanks!
whats updateui
supper_raptor | 2020-04-27 08:47
your code can be converted into
get_node ("Optimize").disabled = (grass < optimize_cost)
this is same as your code but shorter
supper_raptor | 2020-04-27 08:50
Thank you! That’s much cleaner. I’ll be using that from now on. Cheers!
arbitrarybarry | 2020-04-27 15:11