Ensure one script runs before everything else?

I’m working on a game and have run into a problem with the order in which certain scripts and logic bricks are executed. When you start the game from the main menu, the first thing I want done, before anything else, is to set certain objects’ properties that may have been saved last time someone played. For example, all the doors have ‘open’ properties, there’s a score property etc. However, what’s happening is that sometimes the objects in the scene start to update before the initialization script runs, leading to confusion. Some doors end up closed when they’re supposed to be open and whatnot. The weirdest part is that it almost seems random the order in which objects choose to start updating. Sometimes it works out alright, sometimes it doesn’t. Sometimes, half the doors end up updating before the initialization script runs and then the other half update properly afterwards.

Is there any way to make sure one script executes before everything else in the scene?

Press the little “folder icon with a red flag in it” right above your script in the controller panel - “Mark controller for execution before all non-marked controllers”

But it may not be enough.

Thanks haidme, worked perfectly when I tried it, hopefully it will continue to function!

This will work for the object in question, but other objects will be updated as normal, possibly before such controllers.

Hmm strange, it seems to be working fine even with many different objects. Is the controller priority only supposed to work on the object that it’s attached to? Because it doesn’t specify on the tool tip that it gives.

Yes the script priority work only for the object that is attached to. What I’ve done in may game is an empty object called ‘OBinitGame’ and I put all the initialization scripts for the game there. That way I can control witch script to run first. However on some point you may need to add in this ‘OBinitGame’ a delay sensor, for some of your scripts, at least in my case, so that way you can control when to run each of the scripts attached to that object.

PS:In your case it worked perfectly because there is no other object with that priority marked to it. If you mark with that priority another script in another object they will execute in the same time.

Ah thank you that makes a lot of sense. I guess that is true, I have no other script or controller with priority marked.