Godot Version
V 4.6.1
Question
In my Ping-Pong clone I need 1 script to load before the other: I need to load the boxes before assigning signal to them so the game would work properly.
Any script attached to a node will be loaded per scene tree order. You cannot change that.
Global scripts are loaded before them.
So you need to change your scene tree. If you cannot do that, then you need to think and change your game logic.
The first script creates box instances, which is inside the “Main” node, other scripts are located in nodes-children of the Main.
add a signal to the first script that says it’s loaded and add a if statement to the script that must be loaded after - get the refference, and do:
func _ready():
first_script.loaded.connect(later_logic) ## In case it haven't loaded
func later_logic():
if first_script.finished_loading:
## Code here
EDIT: by first_script i mean the node that stores it, keep that in mind cuz you can’t really reference a script
Feel free to correct me if I’m not understanding this properly - you defined a signal in your main class that needs to be listened for in your child class. This is not in line with standard Godot philosophy which is “signal up, call down”.
You can still work around this two ways that I know of. You can use a global signal bus to pass the signal around. Since the bus always exists it doesn’t matter when the nodes emitting the signals are created.
The second way is possible, but I don’t recommend it since it can be fragile. You can ask the parent node for a reference to the signal.
get_parent().custom_signal.connect(signal_handler)
What do you mean by “load”?
i think he means execute scripts, cuz he said he need to load boxes before connecting their signals
What do you mean by “execute”?
umm scripts execute code inside them, like if you have _ready with declaring sum of variables and printing it, you have execution:
That’s not what is unclear here, a whole script doesn’t have an order
What it seems like OP is asking about here is the order of initialization of nodes, which is documented here
Why not just have an autoload, which instantiates a copy of the other required scenes in the order that you want.
Or just use autoloads and order them in the order they need to be.
There’s plenty of ways of doing this.
Yeah but there are various callbacks you can override. Not all of them execute in the same order or at the same point in object’s lifecylce.
execute is just yk, code that runs, like if there’s script that executes before script B, then it’s execution, in short - just coed you want to run :\
That doesn’t answer anything though, I don’t think you are understanding the conversation here
I think it may help:
For loading this probably isn’t relevant, signals and loading doesn’t sound like something they are doing in _process
hmm, yeah. does assigning the signal means this one?
(I am dumb I know : p)
func _ready():
signal_name.connect(something)
No clue in this case as OP hasn’t clarified, but _ready is not affected by the process priority, only the tree order
My guess was that, I will set the priority to -1 and connect the signal like this:
var is_connected:bool = false
func _process(delta):
if !is_connected:
#Do signal stuff here,
is_connected = true
It’s surely badly coded, but that’s the way I was able to think of it xD