Hello, In my game, I have a node called Pet in which I want the Player to catch. When the Player does, I have an event method called in the Pet node's script, where it would delete the Pet instance. However, I also want to call the HUD node's method to determine which of the HUD's labels should be updated.

With the code below, the HUD's _is_capacity_full() is called but always returns false even though it should return true when I run my game. I'm not sure if I had gotten the HUD script correctly and if it may be the problem...

signal pet_collected
signal pet_fallen

onready var hud = load("res://Scripts/HUD.gd")

func _on_Pet_body_entered(body):

	if not hud._is_capacity_full():
		print("Pet has reached Player")
		emit_signal("pet_collected")	# would update the HUD's Label1
		queue_free() # deletes the Pet instance
	else:
		emit_signal("pet_fallen")  # would update the HUD's Label2
		queue_free()

Thank you in advance!

Edit: I found in the debug log this error: Can't call non-static function '_is_capacity_full' in script. So I tried to make that function static but it causes another error saying it can't access the HUD member variable in the static function. Is there a way to resolve that issue?

Basically if you save a script in a variable (I don't know why) you can only call static functions. one way to fix it would be to merge the script into a node

onready var hud = load("res://Scripts/HUD.gd").new()

this is how i fix it in a similar case but i think there are better ways to do it

@TheDiavolo , thank you for responding to my question. I tried that but unfortunately, it would still make _is_capacity_full() always return false since creating an instance of the HUD script would not persist the HUD's member variable value.

Here's what _is_capacity_full() looks like:

func _is_capacity_full():
	return cap_met == CAP_LIMIT

At this point in my game, cap_met is equal to CAP_LIMIT( a non-zero number) and is a non-zero number. But adding .new() to my HUD script instantiation and running my game, cap_met is shown as 0, making the function return false.

a year later