So I'm sure I'm missing a simple solution here but all I am finding is Harlowe's documentation for 'contains' and basic array use, and greyelf's samples on how to use array's. If I wanted to check 'are all the elements in array1 present in array2' how would I do that? (assuming I don't know the the exact lengths of array1 and array2)
I was thinking maybe something like
(if: $ar4 contains (...$ar4))[ar4 contained ...ar4]
(if: ...$ar4 is ...$ar4)[...ar4 is ...ar4]
but that didn't work (didn't expect it to but hoped there would be some overloaded functionality). The only loop I can find in Twine 2 anywhere is the live: stuff (not applicable) and the contains: that does an under-the-hood loop
Comments
Call to function:
The actual base function is fnArrayMatch, it checks that everything on the left exists in the right:
And this calls the recursive function (fnArrayMatchLoop):
And for an exact match just taking the slightly slower performance, faster coding solutions of calling the function from both directions (fnArrayExactMatch):
Not the prettiest or most optimal implementation for sure, but good enough and seems to work
(Oh, the error code stuff in it can be removed, its an error handler / logger I'm building for myself)
$arr1 - $arr2 will return an array which contains just the elements from $arr1 which aren't in $arr2. So if $arr2 contains every element from $arr1 the result will be an empty array.
To test if $arr2 contains every element in $arr1 you could do
To test if $arr2 and $arr1 are identical you can do
Your version didn't work because of the ... before the arrays.
In your example you print error if $ar1 and $ar4 match, but they seem to be identical. Is that a mistake?