if else not working properly?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Forward

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
:bust_in_silhouette: Reply From: MysteryGM

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"