f2k sel 164 Posted August 22, 2009 (edited) I was just trying to compare two arrays and found it quite difficult. I did find some script to do it but I also noticed that there is a Bis_function. call BIS_fn_areEqual I can't seem to get it to function. [_array1, _array2] call BIS_fn_areEqual] should return true or false. I've tried using it in an IF statement and var=[arry1,arry2 ect, but the variable only returns "any" Can anyone work out what's wrong? Edited August 22, 2009 by F2k Sel Share this post Link to post Share on other sites
wamingo 1 Posted August 23, 2009 (edited) I'm no guru on this subject but what is in the arrays? ar1 = [1,2,3]; ar2 = [1,2,3]; result = [ar1,ar2] call BIS_fnc_areEqual; // result = true just tried in a trigger. (remember the Functions module) But the arrays need to be identical I think. for a different kind of dynamic you can look into array subtraction. If the result is empty then each element is in each array [1,2,3,4] - [1,3] = [2,4] [1,1,1,2] - [1] = [2] // ar1 = [1,3,7]; ar2 = [7,1,3]; result = ar1 - ar2; if count result == 0 // should return true with nested arrays you need to compare each element individually I think, maybe using "select" Please take all this with a bit of salt, I've not really used this stuff. hope it was some help though. Edited August 23, 2009 by wamingo 1 Share this post Link to post Share on other sites
f2k sel 164 Posted August 23, 2009 Thanks I'll take a look later. Share this post Link to post Share on other sites
Deadfast 43 Posted August 23, 2009 _arrayCompare = { private ["_array1", "_array2", "_i", "_return"]; _array1 = _this select 0; _array2 = _this select 1; _return = true; if ( (count _array1) != (count _array2) ) then { _return = false; } else { _i = 0; while {_i < (count _array1) && _return} do { if ( (typeName (_array1 select _i)) != (typeName (_array2 select _i)) ) then { _return = false; } else { if (typeName (_array1 select _i) == "ARRAY") then { if (!([_array1 select _i, _array2 select _i] call _arrayCompare)) then { _return = false; }; } else { if ((_array1 select _i) != (_array2 select _i)) then { _return = false; }; }; }; _i = _i + 1; }; }; _return }; Parameters are [array1, array2] Returns true if arrays match, false if not Works with nested arrays as well. Example: _bool = [_array1, _array2] call _arrayCompare; 1 Share this post Link to post Share on other sites