Why I got always an "Invalid get index 'position' (on base: 'null instance')" error messsage?

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

Hello!

I always got thar error message about the ‘position’ variable in this code:
var mousex=get_global_mouse_position().x
var mousey=get_global_mouse_position().y
for j in cards:
if j==null:
continue
elif mousex>j.position.x and mousex<j.position.x+cardwidth and mousey>j.position.y and mousey<j.position.y+cardheight:
The if j==null: isn’t working or what???
Cards is an array in my game thar contains instances of a card node.

:bust_in_silhouette: Reply From: annemarietannengrund
var x = null
if x == null:
	print('prediction 1: x is null')
if typeof(x) == TYPE_NIL:
	print('prediction 2: x is null')
print(typeof(x), ' == ', TYPE_NIL)

results:

prediction 1: x is null
prediction 2: x is null
0 == 0

both, typeof with its variant types and null check look valid.

maybe you can add code tags to your questions, maybe there is an intendation error which could explain the not working continue