Why is any_enemies_in_range alway strue?

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

So basically since program crashes when I try to look at a null object I have decided to only do it when enemies_in_range isn’t null but instead its always true, why?

extends Area2D

var enemies_in_range = []
var any_enemies_in_range = false

func _physics_process(delta):
	if any_enemies_in_range:
	if any_enemies_in_range == null:
		any_enemies_in_range = false
		any_enemies_in_range = true
func _on_turret1_body_entered(body):

func _on_turret1_body_exited(body):
:bust_in_silhouette: Reply From: CharlesMerriam

Your code has an error:

If EIR is null, set it to false until the next call.
If EIR is not null, because you set it to false, then set it true.

So EIR is always true.

oh sorry yea I accidentally set it to any enemies in range instead of enemies in range

lotos | 2021-02-06 11:12