Jump to content
SilentSpike

Do preInit and postInit functions run on all machines?

Recommended Posts

Question is in the title. If I set a function to run preInit or postInit in description.ext does it run on all machines in the network or just the server?

As a bonus question (since it feels like a waste to have a whole thread on this one question), is there a simple way to test for script locality errors? Most of the time I don't have someone else handy to help me and it would be a godsend if there was a simple way to do so alone.

Share this post


Link to post
Share on other sites

Runs on server + clients. So yes, everyone.

Share this post


Link to post
Share on other sites

Thanks, I'll add that into the functions wiki page while I'm at it

Share this post


Link to post
Share on other sites

I wonder if someone could help me on the following: the mod AGM to allow the AI ​​units falling unconscious should be placed on each Init "this setVariable [" AGM Allow Unconscious ", true]" but would i like to have when you load the mission all the units have such code, and not place to each thanks ... (I seen a "InitPost" can be achieved)

Share this post


Link to post
Share on other sites
I wonder if someone could help me on the following: the mod AGM to allow the AI ​​units falling unconscious should be placed on each Init "this setVariable [" AGM Allow Unconscious ", true]" but would i like to have when you load the mission all the units have such code, and not place to each thanks ... (I seen a "InitPost" can be achieved)

This is for functions and the classes within the .hpp file, not for what your trying to do(I don't think anyhow), try looking up adding init lines to multiple AI units and see if anything pops up. If not then just create a new thread. Or look up the forEach command. I mean you could put together a function file and a .hpp file, include it in the description.ext, and call it in the init.sqf, but I think that's a bit more trouble than what you need to accomplish your goal.

Edited by JShock

Share this post


Link to post
Share on other sites

hi,

This topic seems to me the right place to ask my question. Sorry if not.

I created a little function to find nearest enemy along with custom criteria. In Vanilla Apex, here is my description.ext:

class CfgFunctions
{
  class MGI
  {
    class MGI_TEST
    {
      class nearestEnemy
       {
        description = "gros blah blah";
        file = "nearestEnemy.sqf";
      };
    };
   };
  };

 

Everything is OK. No error, so far. NB: This function is called by a line like: [<guy concerned>,<reference position>,<range>] call MGI_fnc_nearestEnemy and works.

Example : [player,player,1000] call MGI_fnc_nearestEnemy

 

But, I tested with postInit = 1 (then preInit = 1 as well) this function. I always catch an error in both cases. I probably didn't understand the concept of these lines.

 

Let me explain the error with preInit or postInit:

The sqf is simple:
 

_guy = _this select 0;
_pos = _this select 1;
_maxRange = _this select 2;
private ["_guy","_pos","_maxRange", "_position","_enys","_MGINearestEnemy"];
_guy = param [0, objNull, [objNull]];
_pos = param [1,[0,0,0],[[],objNull],[2,3]];
_maxRange = param [2,0],[0];

  call {
    if ([_pos] isEqualTypeParams [[]]) exitWith {_position = _pos};
    if ([_pos] isEqualTypeParams [objNull]) exitWith {_position = getPosWorld _pos};
    _position = [0,0,0];
  };

    call {
      if (side _guy == west or side _guy == east) exitWith {
        _enys = allUnits select {side _x getFriend side _guy < 0.6 && _pos distance _x < _maxRange}
      };
     _enys = [];
    };
    _distSqr = _maxRange;
    if (_enys isEqualTo []) then {_MGINearestEnemy = objNull} else {
      for "_i" from 0 to count _enys - 1 do {
        _check = (_enys select _i) distance _pos;
        if (_check < _distSqr) then {_distSqr = _check; _MGINearestEnemy = _enys select _i}
     };
    };
    _MGINearestEnemy

This function still works...

But, as soon as I preview the mission, before calling anything in debug console or a script, I get this error:

14:38:24 Error in expression <pos = _this select 1;_maxRange = _this select 2;private ["_guy","_pos","_maxRa>
14:38:24   Error position: <select 2;private ["_guy","_pos","_maxRa>
14:38:24   Error Zero divisor
14:38:24 File C:\Users\Utilisateur\Documents\Arma 3 - Other Profiles\Kobayashi%20Maru\missions\compileVSfind.Stratis\nearestEnemy.sqf, line 3

 

I tried with:

params [["_guy",objNull,[player]],["_pos",getPosWorld player,[objNull,[]],[2,3]],["_maxRange",50,[0]],"_position","_enys","_MGINearestEnemy"];

 

No more success. Error is now:

14:40:24 Error in expression <compileVSfind.Stratis\nearestEnemy.sqf" params [["_guy",objNull,[player]],["_pos>
14:40:24   Error position: <params [["_guy",objNull,[player]],["_pos>
14:40:24   Error Params: Type String, expected Object
14:40:24 File C:\Users\Utilisateur\Documents\Arma 3 - Other Profiles\Kobayashi%20Maru\missions\compileVSfind.Stratis\nearestEnemy.sqf, line 1

 

 

It seems that preInit or postInit versions are trying to run something before any parameter input, then fail with lack of then of take variable declaration for strings param...

Strange! That doesn't happen without pre/postInit.

 

Thanks for any explanation. Are pre/postInit available for non-parametered functions, only?

 

 

Share this post


Link to post
Share on other sites
2 hours ago, pierremgi said:

I probably didn't understand the concept of these lines.

 

2 hours ago, pierremgi said:

It seems that preInit or postInit versions are trying to run something before any parameter input

 

The pre and post Init are not initialisers or cause the functions to be define at a specific time, they are for actually calling the functions pre and post Init.

So of course using these with your specific functions is not the intended use and the functions will not receive the parameters they require so will fail.

The reason your second example fails with Type STRING expected OBJECT is because when using pre/postInit the STRING "preInit" or "postInit" is sent to the function as param 0.

Share this post


Link to post
Share on other sites

Wow, thank you so much Larrow. I can see a little light at the end of the tunnel.

Pre and post functions in cfgFucntions are running like described in initialization order. Without the init specification, they are running when called.

 

So, I understand an addon (we are now in config.cpp and a cfgPatches is added)  can start with a simple pre/post init function. Is it the normal way to fire the first function in this case (addon)? or is there a standard way to make it run (I mean without pre/post init line)?

 

Thanks also for the param 0 understanding.

Share this post


Link to post
Share on other sites

If its a scripted system addon then postInit is most likely your best bet, this will call the script once everything is up and running. As for is this the normal way... for a scripted system then its most likely a good solution, if its object specific then your likely better starting it from the objects class init EH.

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, pierremgi said:

 


_maxRange = param [2,0],[0];

 


What the.. I don't even..

Share this post


Link to post
Share on other sites
5 hours ago, killzone_kid said:


What the.. I don't even..

Yep, sorry for the typo

_maxRange = param [2,0,[0]];

That probably explains why I didn't get the same error message.

Share this post


Link to post
Share on other sites

Sorry for hijacking this thread.

 

What do the config entries

headerType = -1; //Set function header type: -1 - no header; 0 - default header; 1 - system header.

 

and

description = ; 

 

do?

 

Are they related to the function viewer?

 

description = ; is for example not listed on the wiki page, but BIS is using it for their official functions.

Share this post


Link to post
Share on other sites
headerType

used to set some debug variables before the script, like script parent, name etc. -1 makes it cleaner and faster but no debug info
 

description = ; 

Can drop it, don't think it is used

 

  • Like 1

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

×