I have 3 sprites A, B and C, each one has area2d attached to it and collision shape

the script for A

extends Area2D
var done = 0

func _input_event(viewport, event, shape_idx):
    if event.type == InputEvent.MOUSE_BUTTON \
    and event.button_index == BUTTON_LEFT \
    and event.pressed:
        done = 1

And all like that

Now the main node has a script attached to it

extends Node2D

func _ready():
    if get_node("lA").get("done")==1 && get_node("B").get("done")==1 && get_node("C").get("done")==1:

But it doesn't work, why?

The error when doing if get_node("lA").done == 1 is

Invalid get index 'done' (on base: 'Sprite').

What I'm trying to do is collect some items, when done, move to a new scene


2 Answers 2


According to this QA post you should be able to access your variable doing get_node("node").variable

If that doesn't work try using a getter method for your variable:

var done = 0 setget ,done_get

func done_get()
    return done
  • \$\begingroup\$ I tried the first method, edited my question to indicate that. I should place that function in each of the scripts? and how to call it from the main node script? \$\endgroup\$
    – Lynob
    Commented Jul 29, 2017 at 16:57
  • \$\begingroup\$ You put that function in the script that has the variable done. And you access it like any other function get_node("node").done_get() or by the above method. \$\endgroup\$
    – Charanor
    Commented Jul 29, 2017 at 17:01

The reason why you get an invalid index error is that not your Sprite node holds the done variable but the Area2D node. That means you have to use:

if get_node("1A/Area2D").done == 1 and get_node("B/Area2D").done ...:

If you renamed the Area2D node you must change the names accordingly.

Hope that helps.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .