I have three scenes: Main, Player, and Crop.
My main scene has the tilesets and a few other child nodes linked (including Player and Crop).
My player scene has a Sprite2D and an AnimationPlayer
My crop scene has a Sprite2D.
Inside my Crop scene I have a script that has one variable and one function.
@export var is_watered: bool = false
func _process(_delta):
if is_watered:
$Sprite2D.texture=ResourceLoader.load(image)
is_watered is just a Boolean while the _process function changes the image of the Crop to its next stage.
Inside my Player scene I have an AnimationPlayer that has an animation called water_down. Also inside the Player scene there's a function called water().
func water():
is_watered = true
But because the Player and Crop nodes are different scenes it didn't recognize what is_watered is. How can I change the Boolean inside of Crop to true while using an AnimationPlayer from the Player scene? I tried emitting a signal but that too only connects to nodes inside the same scene.
You could have a separate script that is autoloaded and pass variables through that.
You would save the variable in the autoloaded script and then whenever you want to access it you would just call sciptName.variableName instead of just variableName.
For example, in your case:
Data_transfer.var is_watered: bool = false.Cropscript to use theData_transfer.is_wateredvar:@export var is_watered: bool = Data_transfer.is_wateredThis will allow you to continue to be able to use the
@exportpart of the variable, but since changing it doesn't change the Data_transfer variable you will have to have something like:Data_transfer.is_watered = is_wateredwhen the script is loaded like in the_ready()method. Otherwise, the value of the export won't be used.Cropscript to use theData_transfer.is_wateredvariable instead ofis_watered.Playerscript to useData_transfer.is_wateredinstead ofis_watered.