charliereddog 9 Posted February 14, 2008 How is it that you can minus one array from another, but not check whether that array is in the other one? Share this post Link to post Share on other sites
sickboy 13 Posted February 14, 2008 No idea. But this works: _var = (str(ar1) == str(ar2)); _var will be true if the arrays match and untrue if the arrays don't match. (erhm I must admit im unsure if str(xx) works... you might need to test: (format["%1",ar1] == format["%1",ar2]) instead) Share this post Link to post Share on other sites
charliereddog 9 Posted February 14, 2008 Thanks. That's actually not going to help my problem one bit, but it's useful to file away for the day it will help. My issue is Arr1=[cp1,cp2,cp3,ar1,ar2] Arr2=[ar3,ar4,ar2,ar1,cp1,cp2,cp3] Arr1 in Arr2 doesn't work. Bizarely though Arr2-Arr1 returns [ar3,ar4]. Surely if it can do that, it should be able to work out whether the entries are in the array! Share this post Link to post Share on other sites
sickboy 13 Posted February 14, 2008 so create a function, t_arrayCompare.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private ["_ar1", "_ar2", "_ok", "_bad"]; _ar1 = [] + (_this select 0); _ar2 = [] + (_this select 1); _ok = true; _bad = []; {  if (!(_x in _ar2)) then  {    _ok = false;    _bad = _bad + [_x];  }; } forEach _ar1; [_ok,_bad] preCompile it with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> t_arrayCompare = compile preProcessFile "t_arrayCompare.sqf"; And use the function e.g as: _compare = [ [cp1,cp2,cp3,ar1,ar2], [ar3,ar4,ar2,ar1,cp1,cp2,cp3] ] call t_arrayCompare; _compare variable now contains an array: [ ARRAYMATCH?, UNMATCHEDITEMS] Arraymatch will be true if array2 contained all items from array1 Unmatcheditems contains an array with items in _ar1 but not found in _ar2. You can expand/tweak the function as needed of course, add another loop to turn the test around and capture the differencing objects from both arrays. Quote[/b] ]Arr1 in Arr2 doesn't work. Bizarely thoughArr2-Arr1 returns [ar3,ar4]. Surely if it can do that, it should be able to work out whether the entries are in the array!  so add another check on the output (_result in example): <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (count _result==0) then{  // array2 contained all items from array1 } else {  // array2 did not contain all items from array1 }; Share this post Link to post Share on other sites
loyalguard 15 Posted February 14, 2008 I am not sure of this will help as I only have the most basic of array-related knowledge but it might be something to consider SPON_deepEquals at ofpec.com Quote[/b] ]Description: Â Compares any two values, including nil, null, arrays or nested arrays, for equality. Share this post Link to post Share on other sites
sickboy 13 Posted February 14, 2008 SPON_deepEquals at ofpec.comQuote[/b] ]Description: Â Compares any two values, including nil, null, arrays or nested arrays, for equality. Good point you have there aswell Share this post Link to post Share on other sites