Godot does... weird things with null values

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

I’m currently in the process of trying to port my game to Godot 4.0 - so far its not going too great but it works fine where I’ve went in and manually fixed the issues. But this is one I just cannot fix no matter what. See attached image.

Any ideas on how to fix this?
edit: sorry if my handwriting’s a bit hard to read. error is “Expression is of type “null” so it can’t be of type “Callable””.

Are you sure your the error is happening in the code snippet shown in your pic? I don’t see how / why that should be the case and I don’t see anything there related to a callable

jgodfrey | 2022-10-29 14:28

:bust_in_silhouette: Reply From: AlexTheRegent

I think your problems is in order of operations. First you trying to check if i-th instance is valid, and only after it you trying to check if i is not null. Expressions are evaluated from left to right and you should simply first check if i is null and only then attempt to check if i-th instance is valid. I.e. change your if from this:
if is_instance_valid(i) and not(i is null):
to
if not(i is null) and is_instance_valid(i):
also you can probably replace not(i is null) with i != null