(SOLVED) What is the best way to ensure the game manager script is the first one to be initialized?

So I have a system where I create attributes for various items (like missiles for example). These missiles are creating by a factory that I have on my main collection.

My game manager sets the attributes via a lua module, but the issue is for some reason the missiles are “generated” before the game manager gets to set the attributes.

Even if I have the GO disabled then enable it by the game manager this still happens.

What is the best way to ensure the game manager script is the first one to be initialized?

:thinking: You could try a conditional…

 isNightTime = false

 if isNightTime then

    print("Good night!")

 else

    print("Good morning!")

 end

 -- This statement prints "Good morning!" because the if condition evaluated to false.

I don’t think that would do it as these are different scripts and objects. Unless I misunderstand your comment.

If you use logic, it might work for you. :wink:
I’ll leave it for homework! :nerd_face:

Since the missiles are spawned from a factory (and presumably that factory is triggered from the manager script), they should always be initializing after the game manager script. Maybe there’s some detail with how the attributes are set and fetched that’s causing issues?


Posting an AI-generated response and then insulting the OP because you couldn’t be bothered to read or write isn’t a good way to stay on a forum.

3 Likes

@britzl This is the second thread by Visionaire I’ve seen him in…he’s just disruptive.

3 Likes

That’s the odd thing…it appears they are getting their attributes first thing maybe because they are first in the hierarchy. Bullet_factories are first. But you’re right they don’t spawn until something is in range. But the attributes are nil. Even when I disable the factories via the game manager and then enable them once the game manager is initialized. I must be doing something wrong.

See:
image

The order in the outline shouldn’t determine which order they load in (the devs explicity don’t want that to be the case: Declare first script to load in a collection · Issue #8581). Could you share the code for getting/setting the attributes?

So my question really is what is the best way to implement a game manager? Since clearly I shouldn’t rely on scripts being loaded first.

So based on what you provided, It sounds like I need to use a proxy collection and manage the first scripts from there.:

E.g. when the boostrap script has been called, and the collection proxy has loaded the map/level, then you enable the collection by sending events “init” and “enable”.
After that, you know that all scripts are setup, you can then send a message to which ever script in that proxy to “start” the next set of events.

Another option I’ve seen is to have the script you want loaded first send out a late_init message to the other scripts so that they’re guaranteed to initialize later.

1 Like

Thanks. I’ll give that a try first as that appears easier to do.

What does the game manager do? Is it a go script or a lua module? I expect it’s a lua module where you store ids in a table after factory.create()

I think I figured it out. I have an issue in my lua module. Where I thought I could give it an object and assign multiple attributes to that object. But really it was setup to only take one attribute per object. So the last line was winning.

I’m re-writting the module to accept more than one attribute per object.