How to export a variable from another scene in a simple way.

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

I made a simple dialog system, and I wanted that when the dialog was happening the Player would stop, so I made a variable in the Player that it could only move when this variable was FALSE, but I wanted to be able to enable the NPC to enable it when it starts the dialog and disable at the end.

:bust_in_silhouette: Reply From: petermoyle

It’s worth learning about signals

Although it turns out connecting a signal to another scene is a bit more work than i expected.

How does the player trigger the NPC? Is there an CollisionShape? If so you can call a function on the body that is detected.

So add this to the player

func npc_talking(is_talking):
	cant_move = is_talking

Then call it passing a true of false from your detection code.

:bust_in_silhouette: Reply From: SnapCracklins

You could use a Singleton in an autoload. Make a script named “Global” and attach it to a Control or Node2D, then autoload that in settings. (The object, not the script)

Then it’s as simple as this:

var _currentCutScene = false ## you can name this whatever

Then a simple check in your character’s movement, you can also put an extra variable there if you’d like. This is usually a good idea with singletons because calling them is a reference unless yo are directly changing it. If the bool is true, don’t allow movement.

if _currentCutScene == true:
     _canMove = false

Then plug that into whatever functions you want to disable.