0 votes

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:
        get_parent().hide()
        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:
            get_tree().change_scene("res://scenes/scene2.tscn")

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

in Engine by (12 points)
edited by

I push comment Button by mistake, but i want do an answer....

2 Answers

0 votes

You should be able to access a variable like this:

get_node("SomeNode").variable

So in your instance:

if get_node("lA").done == 1
by (306 points)

tried that, the scene stops working, at least in my question above, everything works except the script

I am not sure you can have more than the event parameter in processinput() but maybe if you could post your errors it would be easier to pon point your problem, and maybe some more explaining as your initial question is how to access a variable in another script.

please read my edit

+2 votes

You are trying to get a variable in the sprite, but the variable is in the area, because the script is in the area (2 nodes after main node). The correct path is get_node("1a/area2d") or whatever ... Sprite doesn't have "done" variable.

by (341 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.