If not using autoload, is there other ways using var to other scripts?!

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

Finally, understood. I didnt think that is about all the other objects. So i wanna know other ways. For example, i wanna use from var in “A.gd” to “B.gd”,s var. And if A’s var is changed, B’s var also changed too. Not use autoload. How can i do this?! I was googling, but couldnt solve this. In “load” or “preload” coding way, i can load inital setting var but i cant load updated var values. Plz help me.

:bust_in_silhouette: Reply From: crossbito

You can use custom signals to create a signal that triggers when a variable changes and connect it with another script.

For example, in A.gd:

signal varHasChanged(oldValue, newValue)
var myValue

func varChange(newValue):
    var old_value = myValue
    myValue = newValue
    varHasChanged.emit(old_value, newValue)

Then, connect the signal with the other script and implement the desired functionality in B.gd (you can connect it using code or the inspector).

Here it’s the documentation for signals