Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | 1tokenblackguy |
so I have a game mechanic im playing with at the moment. I have a harvester moving from its spawn point to the nearest mine and then back to the spawn point. (think command and conquer harvester ) my problem is i have the resources node detecting if it has been entered and starting a counter every 5 second it decreases its remaing gems by one. when it gets to 0 i want it to queue_free and update the list of nodes in the array. However it just crashes when i use
"if Remaining_gems ==0:
queue_free()"
the code in the Gem node is:
extends Area2D
var Remaining_gems = 5
func _ready() -> void:
pass # Replace with function body.
func _process(delta: float) -> void:
$Label.text = str(Remaining_gems)
print(Remaining_gems)
if Remaining_gems ==0:
queue_free()
func _on_Timer_timeout() -> void:
if Remaining_gems > 0:
Remaining_gems = Remaining_gems - 1
elif Remaining_gems == 0:
Remaining_gems = 0
func _on_Gem_body_entered(body: Node) -> void:
$Timer.start()
func _on_Gem_body_exited(body: Node) -> void:
$Timer.stop()
the code in the Main level is
func _ready() -> void:
Fruit.append_array($GemPoints.get_children()
func _process(delta: float) -> void:
$Label.text = str(Remaining_gems)
print(Remaining_gems)
if Remaining_gems ==0:
$Timer.stop() // just try
queue_free()
and Maybe
The problem must be elsewhere.
if Remaining_gems == 0
other place is using here and when equal to Zero the problem occurs
Sample
Fruit.append_array($GemPoints.get_children()
$GemPoints.get_children
Maybe it’s causing trouble because he doesn’t have children.
I hope I was able to explain
ramazan | 2022-03-08 11:05