New Answer
The underlying reason of the problem is that the autoload (singleton) script is not the same on the scenario. When the player interacts with the instance on the scenario, the green door script interacts with the instance on autload (singleton).
There are a two solutions:
Option one: Don't use an autoload.
Now that green button has signals (as suggested in the original answer, kept for reference), you can connect them directly to the green door, or doors, in the scenario from the editor.
You would no longer need to connect those signals from code if you do it from the editor, of course.
Drawback: It can get complicated to connect all the signals for large scenarios.
Option two: Use a signal bus.
For those complicated large scenarios, there is a a common pattern in Godot: the signal bus.
To do it, you create a script and put in autoload (singleton), and that script will only defines signals. Nothing more. You would then emit those signals and connect them whenever you need them (knowing that being a singleton they are always available).
Let us say your singleton is called SignalBus
(because, of course), and it has the signals "button_down"
and "button_up"
then in your green button code you can do this:
func _on_Green_Button_Area_body_entered(body):
SignalBus.emit_signal("button_down")
print("button is down")
func _on_Green_Button_Area_body_exited(body):
SignalBus.emit_signal("button_up")
print("button is up")
And in your green door code, you can connect to the SignalBus
:
onready var door_collision = $CollisionPolygon2D
func _ready() -> void:
SignalBus.connect("button_down", self, "_on_button_down")
SignalBus.connect("button_up", self, "_on_button_up")
func _on_button_down():
door_collision.set_disabled(true)
print("unlocked")
func _on_button_up():
door_collision.set_disabled(false)
print("locked")
And that would be connecting all the green doors to all the green button via the signal bus.