Topic was automatically imported from the old Question2Answer platform.
Asked By
Megatt4
I tried to import a variable from a script to another but for some reason it’s giving me an error, saying that the script is null
here’s the code from the script i’m trying to access the variable:
onready var GridSizeUI_Script = load("res://Scripts/Grid_Size_UI.gd").new()
#Size of grid in a 1x1 basis ( User Input )
var GridSize = GridSizeUI_Script.NT
First variable is ONREADY so it comes later than second variable.
Try to make GridSize onready also. However it still may be too slow, because you are both loading and creating instance of new script.
Removing the Onready on the first var worked! Thanks a lot!
I didn’t understand what an “Onready” var meant exactly so thanks for the explanation too!
Megatt4 | 2021-10-06 00:37
onready var is the same as you would introduce value of a viariable in on_ready() function
It is mostly usefull for variables keeping references to children or parent nodes, because when referenced node is not ready at the moment od variable introduction - it will return null for the rest of running project. “Onready” keyword waits for the referenced node to be ready, so the variable can return this node.