I’d like to apologise for the lack of blog posts recently, be my guest and blame Putin for it. So today I’d like to show you something cool and very useful. What is really amazing about Arma is that an obvious solution could be lying in plain sight for ages yet be so hidden until one day it just presents itself.
Today I was playing with switch do case structure. I mostly neglected it because of the speed (if then is faster). Apparently if you finish case statement with ; ignoring usual block of code {}, if this case is matched, the script will drop to the next case containing block of code {} and execute that block. If there is no case with the block of code {} to follow, it will execute default block of code {}. If there isn’t default, nothing will happen, obviously.
So what this has to do with KK_fnc_isEqual? As you already undoubtedly know, in Arma you cannot compare booleans and arrays with your usual == or != operators. If you try anything like true != false or [1,2,3] == [1,2,3] you will get an error. But hold on a second, switch do case on the other hand uses, and I think I won’t be wrong calling it, binary comparison. This is why it is case sensitive, means both variables have to be identical. In addition switch do case takes anything as argument (nil gets ignored), so you can compare anything to anything without getting errors like you do with == or !=.
Long story short, using switch do case you can compare booleans and arrays, and not just arrays, but multi-dimensional arrays! And all this time since Arma existence the solution was right there in plain view. I will be asking BIS people to include it in Arma 3 default functions. Or maybe it is better to ask to wrap it in a new command ANY isEqualTo ANY? Think it might be better. But for now, grab it here:
A few tests:
Enjoy,
KK
EDIT: Victory!!! isEqualTo command is officially available on the DEV branch from today and soon will be heading to the main branch. If you need the same functionality for Arma 2, you can still use my function. I’d like to say big thanks to Jan Marecek a.k.a. japapatramtara for splendid work!
EDIT2: A bit late but still could have been another method of comparing arrays (Arma 3 only) if isEqualTo wasn’t added. Basically doing something like array1 in [array2] produces the same result and is as fast as isEqualTo: