This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hi, i'm new to Godot
This is my first Godot project. Its for my school project
I working on a farming game
What i want to do here is disabling a button if the coin variable is less than 25. The concept of that looks like this: You don't have enough money = you can't buy the item
Here is the code:

extends Node

func _process(delta):
  If Global.coin < 25:
    $parent/BuyButton.disabled = true

But, when i run the game, and click a button that decrease coin variable until the coin value is below 25, its shows an error message: Invalid set index 'disabled' (on base: 'null instance') with value of type 'bool'.
How do i fix that?

P.S: Sorry if my question looks un-specific(or have bad grammar)

Godot version 3.5.0
in Engine by (12 points)

1 Answer

0 votes

The message says that the node you are trying to get via $parent/BuyButton was not "found".

if you try to get the parent node, it would be get_parent().get_node("BuyButton").disabled = true

by (64 points)

Im just going to try it without the getting the parent:

extends Node

func _process(delta):
  if Global.coin < 25:
    get_node("BuyButton").disabled = true

and still the same error

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.