0 votes

Can someone explain to me why both of these are triggering at the same time?

If this area is touching both tiles and a player at the same time the elif seems to be getting read first. How come the first if statement is not getting read and not setting added = true? That should then stop the elif from running or is my logic off here?

func _on_Area2D_body_entered(body):
if body.is_in_group("tiles"):
    added = true
    queue_free()
elif body.is_in_group("player") and added == false :
    queue_free()
    wait_seconds(1)
    player[0].velocity.y = -350
in Engine by (39 points)

1 Answer

0 votes

If this area is touching both tiles and a player at the same time the elif seems to be getting read first.

Just tested elif, the order is correct. It checks the bools correctly so this could be something else.

I think the groups here could be what is causing the bug. Or your added variable. Because if the object isn't in "tiles" it will never be added.

This is the test I did.

func _on_Button_pressed():
if int (get_node("TextEdit").text) > 10:
    get_node("Label").text = "High"
elif int (get_node("TextEdit").text) < 20 and SmallerThanT == false:
    SmallerThanT = true
    get_node("Label").text = "Mid"
elif int (get_node("TextEdit").text) < 6 and SmallerThanT == true:
    SmallerThanT = false
    get_node("Label").text = "low"
by (1,482 points)
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.