0 votes

Sorry if this is REALLY stupid, I'm not good.

extends Area2D



var timer = Timer.new()

func _on_[COIN]_body_entered(body: Node) -> void:
    queue_free()
    get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").show()

if get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").show():
    timer.connect("timeout",self,"do_this")
    timer.wait_time = 3
    timer.one_shot = true
    add_child(timer)
    timer.start()

func do_this():
    get_parent().get_parent().get_node("Node2D/[COIN]Counter/UI").hide()

[COIN]

is just a placeholder to make this more readable, if that's possible.

Godot version v3.5.stable.official [991bb6ac7]
in Engine by (34 points)

1 Answer

0 votes
Best answer

Queue free deletes the node and its children, including the timer, so it never times out.

by (8,528 points)
selected by

How would I go about rearranging this or changing it to make it only delete the collectible? Thanks.

P.S. Sorry for the late response.

hide the coin instead of deleting it, and then free it when the timer times out

The other comment has been hidden, cuz' I actually figured THE WHOLE THING out:

    extends Area2D



var timer = Timer.new()

func _on_GeluLumenLapis_body_entered(body: Node) -> void:
    hide()
    $CollisionShape2D.set_deferred("disabled", true)
    get_parent().get_parent().get_node("Node2D/LapisCounter/UI").show()
    timer.connect("timeout",self,"do_this")
    timer.wait_time = 3
    timer.one_shot = true
    add_child(timer)
    timer.start()

func do_this():
    get_parent().get_parent().get_node("Node2D/LapisCounter/UI").hide()
    queue_free()

Thanks for the help, though.

EDIT: Better code that doesn't break when touching a second collectible.

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.