Jump to content
tortuosit

Execution order of spawned scheduled environment, how to workaround?

Recommended Posts

Hi guys,

 

I execvm a script on mod level in an "autostart" kind of way via an addon. The script includes a spawn{} - if the handle already exists, the spawned environment is terminated and then starts again. This way I can run it with new parameters as often as I want.

 

if (!isNil "tort_xy") then {
   if (!scriptDone tort_xy) then {
      terminate tort_xy;
      waitUntil {scriptDone tort_xy};
   };
};
tort_xy = [newargs] spawn {[...]};

 

So now I sometimes add the same execvm to an init field inside the Eden editor. Now what I found out is, after mission start, this is going to be executed first. Then the code from the addon level is executed, i.e. it kills the spawned environment from Eden level. A quick workaround is that a add a small sleep to the Eden code, so it runs after the addon code. But, is there... a cleaner solution? I wanted to prevent using another global variable... And with the workaround of the sleep(), it does certain things twice, which is not beautiful.

 

Thx

Share this post


Link to post
Share on other sites

You can preInit of postInit your functions included in your addon. In your case, you could postInit this one.

Edit: sorry for too fast writing, read preinit.

Edit Edit: Or perhaps not, depending on what you want to do. I'm a little bit lost.

  • Like 1

Share this post


Link to post
Share on other sites
19 hours ago, tortuosit said:

if (!scriptDone tort_xy) then {

Shouldn't be needed. Terminate shouldn't care if you pass in a script that's already terminated.

 

19 hours ago, tortuosit said:

Then the code from the addon level is executed

How do you execute the code from addon level?

 

14 hours ago, pierremgi said:

In your case, you could postInit this one.

Actually not.

 

19 hours ago, tortuosit said:

Now what I found out is, after mission start, this is going to be executed first. Then the code from the addon level is executed, i.e. it kills the spawned environment from Eden level.

Sounds like he want's the addon one to execute first. Meaning preInit.

Share this post


Link to post
Share on other sites

Yes yes,  pre/postinit was a hint into the right direction, thanks guys. The prior code in config.cpp is not worth talking about, I did not know 100% what I was doing. Copy/paste code. I use "call compile postprocesslinenumbers" in order to call init.sqf (which starts the scripts via execvm),... something like this.

 

Yes, I want preinit and it works. 

 

This is how config.cpp now looks - it calls init.sqf inside the pbo which does only include an init.sqf outside of the pbo. This config business is the stuff least understood by me.

 

// tort_autostart 

class CfgPatches
   {
   class TORT_autostart
      {
      units[] = { };
      weapons[] = { };
      version = "1.0.0";
      versionStr = "1.0.0";
      versionDesc= "tort_autostart";
      versionAr[] = {1,0,0};
      author = "tortuosit";
      };
   class TORT_autostartDebugConsole
      {
      units[] = {};
      weapons[] = {};
      requiredVersion = 1.0;
      requiredAddons[] = {};
      };
   };

enableDebugConsole = 2;

class CfgFunctions
{
   class TORT_autostart
   {
      class main
      {
         class preInit
         {
            preInit = 1;
            file = "\TORT_autostart\init.sqf";
         };
      };
   };
};
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 22.8.2018 at 11:42 PM, pierremgi said:

You can preInit of postInit your functions included in your addon. In your case, you could postInit this one.

 

OK, I could not test because my GTX970 too often decides to stops working (no video signal) after mission start regularly now :(

 

May I ask, when exactly is init.sqf executed in my case, as called in config.cpp above?

 

To me it looks like it is executed already in the main menu window, because I can see it applied in the background. Then, will it be executed at ANY mission start again (I need that)?

How would I prevent code to execute before mission start (because I don't need to run it before mission)?  Should I use "waituntil {alive player}"? Or check that that mission timer, if > 0? I remember there are also state variables about the current ArmA state... So, this question is about best practise.

Share this post


Link to post
Share on other sites
3 hours ago, tortuosit said:

May I ask, when exactly is init.sqf executed in my case, as called in config.cpp above?

 

init.sqf is a bad name. There are preInit, Init, PostInit.
Calling your preInit function init is confusing.

 

your "init.sqf" that is executing at preInit. Is executing at preInit (Hah.. Funny..)

PreInit runs before init.sqf, And before editor placed objects are spawned. Before Module functions are executed, before unit init scripts run.

 

3 hours ago, tortuosit said:

To me it looks like it is executed already in the main menu window, because I can see it applied in the background.

Yeah that to. Unless you start with -world=empty.
Because Arma loads a mission behind the main menu.

 

3 hours ago, tortuosit said:

Then, will it be executed at ANY mission start again

Yes

 

3 hours ago, tortuosit said:

How would I prevent code to execute before mission start (because I don't need to run it before mission)?  Should I use "waituntil {alive player}"?

That would be about what postInit does. I thought you wanted it to run before Editor unit init scripts.
waitUntil alive player would wait till after the unit init scripts.

 

Unless you put the waitUntil inside your spawned script. So that the script from unit init will kill it again.

But you still need your preInit to run before mission start.

Share this post


Link to post
Share on other sites
4 hours ago, Dedmen said:

Because Arma loads a mission behind the main menu.

Now that is what I was overlooking and not aware of! Great, now it's all clear I think.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×