0 votes

So basically since program crashes when I try to look at a null object I have decided to only do it when enemiesinrange 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:
        print(any_enemies_in_range)#look_at(enemies_in_range[0].get_pos())  
    if any_enemies_in_range == null:
        any_enemies_in_range = false
    else:
        any_enemies_in_range = true
func _on_turret1_body_entered(body):
    enemies_in_range.append(body)

func _on_turret1_body_exited(body):
    enemies_in_range.remove(0)
Godot version 3.2.3
in Engine by (26 points)

1 Answer

0 votes
Best answer

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.

by (157 points)
selected by

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

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 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 webmaster@godotengine.org with your username.