Jump to content

Recommended Posts

Hi,

I'm in trouble with what I guessed a simple code but my double loop doesn't work.

 

Aim: make all foot units and land vehicles without collision. Don't crush any body.

To start, i did it simple: SP context.

Repeatable simple scenario: On map: a Hunter player, 1 or 2 empty Hunter. (or any vehicle you want). 3 civilians.

 

I run this simple code:

0 = [] spawn {
result = [];
      {
        _veh = _x;
          {
            _unit = _x;
            _veh disableCollisionWith _unit;
             result pushBack [_veh,_unit];
          } forEach (allUnits  select {isNull objectParent _x});
      } forEach (vehicles select {_x isKindOf "landVehicle" && !(_x isKindOf "WeaponHolderSimulated")});
hint  str result;
};

 

I obtain the hint for every couple (vehicle,civilian) but the weird thing is:

- only one vehicle is fully collision disabled with the whole civilians; (last loop checked I guess)

- the other vehicles are collision disabled with the last civilian (last checked probably), but not with the other ones.

 

I did a full day of tests, coming from MP environment, as it was supposed to loop for spawned units. then simplify everything up to this basic test.

 

Testing further, for variables:

 

0 = [] spawn {
  result1 = [];
  result2 = [];
  private ["_veh","_unit"]; // doesn't make any difference
     {
      _veh = _x;
        {
          _unit = _x;
          [_veh,_unit] spawn {
            params ["_car","_man"];
            _car disableCollisionWith _man;
             result1 pushBack [_car,_man];
           };
           result2 pushback [_veh,_unit];
        } forEach (allUnits  select {isNull objectParent _x});
      } forEach (vehicles select {_x isKindOf "landVehicle" && !(_x isKindOf "WeaponHolderSimulated")});
hint (str result1 + str result2);
};

 

Now, my results are:

- result1 = [];

- result2 is a consistent array of couple (vehicle,unit)!!!

 

Any idea? Thanks

 

 

 

 

 

Share this post


Link to post
Share on other sites

I kindly request your skill before adding something at BIKI:

 

So, first of all, here is a little test, simple nested loops, out of any object manipulation. All results are OK for simple variables:

In debug console:

 

0 = [] spawn {
  arr1 = ["a","b","c"];
  arr2 = ["x","y","z"];
  private ["_datumOut","_datumIn"];   
  result1 = [];
  result2 = [];
  result3 = [];

  {  
    _datumOut = _x;  
    {  
      _datumIn = _x;  
      result1 pushback [_datumIn,_datumOut];
      [_datumIn,_datumOut] call {
        _datumIn = _this select 0;
        _datumOut = _this select 1;
        result2 pushBack [_datumIn,_datumOut];
      };
      [_datumIn,_datumOut] spawn {
        _datumIn = _this select 0;
        _datumOut = _this select 1;
        result3 pushBack [_datumIn,_datumOut];
      };
    } forEach arr1;
  } forEach arr2;  
  sleep 0.001;
  hint (str result1 + toString [92,110] + str result2 + toString [92,110] + str result3);
};

 

Note: if no pause before hint, the spawned code (result3) returns []. The hint fires immediately and no spawned code has time to pushback something.

A very little pause makes hint OK. So result3 can't be usable before the pause  >> the end of the nested loops doesn't mean the spawned codes are done. Normal.

 

Then Re-tested with some command f(x,y) type,  like disableCollisionWith:

 

    replacing arr1 = allUnits;  arr2 = vehicles;

    for 1 player in a hunter, 2 empty Hunter more to jump into them,  3 civilian foot units; // very light mission!

    and adding nested code in loop at core scope ( but direct method or called or spawned):

            _datumIn disableCollisionWith _datumOut;

Spoiler

0 = [] spawn {
  arr1 = allUnits;
  arr2 = vehicles;
  result1 = [];
  result2 = [];
  result3 = [];
   
  {  
    _datumOut = _x;  
    {  
      _datumIn = _x;  
      result1 pushback [_datumIn,_datumOut];
      _datumIn disableCollisionWith _datumOut;
      [_datumIn,_datumOut] call {
        _datumIn = _this select 0;
        _datumOut = _this select 1;
        result2 pushBack [_datumIn,_datumOut];
      };
      [_datumIn,_datumOut] spawn {
        _datumIn = _this select 0;
        _datumOut = _this select 1;
        result3 pushBack [_datumIn,_datumOut];
      };
    } forEach arr1;
  } forEach arr2;  
  sleep 0.2;
  hint (str result1 + toString [92,110] + str result2 + toString [92,110] + str result3);
};

 

The behavior is always the same. For any method: direct, called, spawned code:

- The last Hunter in external loop is fine: no collision at all,

- all other vehicles (any number) fail with all the units but the last, in internal loop: (same last unit for all the vehicles). Just one disabled collision case by vehicle.

 

So, I guess this kind of command can't work at core of nested loops.

The failure/success for the couples of variables is predictable! (But not explainable for me).

Any idea to make that work?

Thanks

 

 

 

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

×