WLF Posted May 1, 2019 Report Share Posted May 1, 2019 Hi all! How can I check the out of range in arrays? _a = [0,1]; for "_i" from 0 to 3 do { _c = _a select _i; if (_c ???) exitWith {systemChat "Out of range!";}; systemChat format ["_a[%1] = %2",_i,_c]; }; Link to comment Share on other sites More sharing options...
0 JasonTM Posted May 1, 2019 Report Share Posted May 1, 2019 Modify your for loop so you don't go out of range. for "_i" from 0 to (count _a - 1) do { Link to comment Share on other sites More sharing options...
0 WLF Posted May 1, 2019 Author Report Share Posted May 1, 2019 7 minutes ago, JasonTM said: Modify your for loop so you don't go out of range. for "_i" from 0 to (count _a - 1) do { no, i need to do exactly that. Link to comment Share on other sites More sharing options...
0 JasonTM Posted May 1, 2019 Report Share Posted May 1, 2019 I don't understand what you are trying to do. If you run that for loop you will get a zero denominator error because you are trying to access an element that does not exist. You have 2 elements in the array and you are trying to run the loop 4 times (from 0 to 3). Link to comment Share on other sites More sharing options...
0 WLF Posted May 1, 2019 Author Report Share Posted May 1, 2019 1 hour ago, JasonTM said: I don't understand what you are trying to do. If you run that for loop you will get a zero denominator error because you are trying to access an element that does not exist. You have 2 elements in the array and you are trying to run the loop 4 times (from 0 to 3). I make an example of real script: _donn_carsConvy = [ ["HMMWV_M1151_M2_CZ_DES_EP1_DZE",3], ["UAZ_Unarmed_UN_EP1",1], ["ArmoredSUV_PMC_DZE",2], ["Ural_UN_EP1",5], ["LandRover_Special_CZ_EP1",0] ]; // Cars in each convoy (_refere to donn_carsConvy) _convoyFormation = [ [0,1,2], [4,3], [2,4,2,0] // ,[4,5,6] ]; for "_cs" from 1 to (count _convoyFormation) do { _convoy = _convoyFormation select (_cs-1); _qtd = count _convoy; _cars = []; { _this_car = _donn_carsConvy select _x; // so what if the user makes a mistake and prints a non-existent car? // (uncomment last line in _convoyFormation). // I need to check this. _cars = _cars + [_this_car]; } forEach _convoy; _donn_motor = []; for "_n" from 1 to _qtd do { _car = _cars select (_n - 1); // _motor = createVehicle [_car select 0, position player, [], 10,"NONE"]; _motor = _car select 0; _donn_motor = _donn_motor + [_motor]; }; diag_log format ["Convoy #%1: %2",_cs,_donn_motor]; }; Link to comment Share on other sites More sharing options...
0 Schalldampfer Posted May 2, 2019 Report Share Posted May 2, 2019 Checking isNil "_c" may work? Link to comment Share on other sites More sharing options...
0 WLF Posted May 5, 2019 Author Report Share Posted May 5, 2019 On 5/2/2019 at 12:25 PM, Schalldampfer said: Checking isNil "_c" may work? Yes, it works! Thx! Schalldampfer 1 Link to comment Share on other sites More sharing options...
Question
WLF
Hi all!
How can I check the out of range in arrays?
Link to comment
Share on other sites
6 answers to this question
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now