isEqualTo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(add note)
m (Some wiki formatting)
 
(110 intermediate revisions by 14 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma3 |= Game name
|game1= arma3
|version1= 1.16


|1.16|= Game version
|gr1= Variables


____________________________________________________________________________________________
|descr= Performs strict comparison between var1 and var2 and returns [[true]] if equal, otherwise [[false]]. Strict means that it would check that both arguments are of the same data type and then compare the values.<br><br>
Some differences between [[isEqualTo]] and [[==]]:
* It performs case sensitive comparison on [[String]]s
* It doesn't throw error when comparing different types, i.e. ("eleven" [[isEqualTo]] 11)
* It can compare [[Array]]s, [[Script Handle]]s and [[Boolean]]s ([[alive]] [[player]] [[isEqualTo]] [[true]])
* It can compare non-existent game objects ([[grpNull]] [[isEqualTo]] [[grpNull]])
* It is slightly faster than [[==]], especially when comparing [[String]]s
* {{GVI|arma3|1.48|size= 0.75}} It can compare [[Namespace]]s


| Performs strict comparison between var1 and var2 and returns [[true]] if equal otherwise [[false]]. |= Description
{{Feature|informative|A compiled code is not equal to the same compiled code made final: <sqf>_a = compile "123"; _b = compileFinal "123"; _a isEqualTo _b; // false</sqf>}}
____________________________________________________________________________________________
{{Feature|warning|When comparing [[Array]]s, if an array contains [[nil]] element, the comparison will return [[false]]. For example:<br>
<sqf>
private _array1 = [1, nil, 2];
private _array2 = [1, nil, 2];
_array1 isEqualTo _array2; // false
</sqf>
<u>UNLESS</u> the compared arrays are the same array:
<sqf>
private _array1 = [1, nil, 2];
private _array2 = _array1;
_array1 isEqualTo _array2; // true
</sqf>
See: [[isEqualRef]] and [[BIS_fnc_areEqual]] vs [[BIS_fnc_areEqualNotNil]]
}}


| var1 '''isEqualTo''' var2 |= Syntax
|s1= val1 [[isEqualTo]] val2


|p1= var1: [[Anything]] |= Parameter 1
|p1= val1: [[Anything]]
|p2= var2: [[Anything]] |= Parameter 2


| [[Boolean]] |= Return value
|p2= val2: [[Anything]]
____________________________________________________________________________________________
 
|x1= <code>_arr1 = [1,[2,[3]]];
_arr2 = [1,[2,[3]]];
[[if]] (_arr1 [[isEqualTo]] _arr2) [[then]] {[[hint]] "Arrays match!"}</code> |= Example 1


____________________________________________________________________________________________
|r1= [[Boolean]]


| [[Operators]], [[in]], [[find]], [[set]], [[resize]], [[switch]] |= See also
|x1= <sqf>
_arr1 = [1, [2, [3]]];
_arr2 = [1, [2, [3]]];
if (_arr1 isEqualTo _arr2) then { hint "Arrays match!" };
</sqf>


|x2= <sqf>
if (a isEqualTo b) then { hint "a is equal to b" };
if !(a isEqualTo b) then { hint "a is not equal to b" };
</sqf>
|seealso= [[isNotEqualTo]] [[isEqualRef]] [[isEqualTypeAll]] [[isEqualTypeAny]] [[isEqualType]] [[isEqualTypeParams]] [[isEqualTypeArray]] [[a == b]] [[Operators]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= Tajin
<!-- Note Section BEGIN -->
|datetime= 20141203131100
<dd class="notedate">Posted on Apr 15, 2014 - 16:24
|text= Simply put, "isEqualTo" is a binary comparison. Therefor it is very fast but only accepts '''100%''' identical matches. In some other languages this is known as "&#61;&#61;&#61;" instead of "&#61;&#61;".
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
}}
For multiple comparisons, we can use the example below for more accurate compare than [[BIS_fnc_arrayCompare]] or [[BIS_fnc_areEqual]]:
<code>
Fnc_areEqual = {
Private ["_b","_var1","_var2"];
_b = true;
For [{_i=1},{_i < (count _this) && _b},{_i=_i+1}] do {
      _var1 = _this select (_i-1);
  _var2 = _this select _i;
      If (!(_var1 isEqualTo _var2)) then {_b = false;};
};
_b
};
["A","a","a"] call fnc_areEqual; // false
["A","a","a"] call BIS_fnc_areEqual; // true
</code>
<!-- Note Section END -->
</dl>


<h3 style="display:none">Bottom Section</h3>
{{Note
 
|user= Dedmen
 
|datetime= 20161103023900
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
|text= When comparing with nil result is [[Nothing]].
[[Category:Arma_3:_New_Scripting_Commands_List|{{uc:{{PAGENAME}}}}]]
<sqf>nil isEqualTo player;</sqf>
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
Returns [[Nothing]] instead of expected [[false]]
<sqf>diag_log [nil isEqualTo player];</sqf>
Will print {{hl|[bool]}}
}}

Latest revision as of 10:01, 29 December 2022

Hover & click on the images for description

Description

Description:
Performs strict comparison between var1 and var2 and returns true if equal, otherwise false. Strict means that it would check that both arguments are of the same data type and then compare the values.

Some differences between isEqualTo and ==:
A compiled code is not equal to the same compiled code made final:
_a = compile "123"; _b = compileFinal "123"; _a isEqualTo _b; // false
When comparing Arrays, if an array contains nil element, the comparison will return false. For example:

private _array1 = [1, nil, 2]; private _array2 = [1, nil, 2]; _array1 isEqualTo _array2; // false
UNLESS the compared arrays are the same array:
private _array1 = [1, nil, 2]; private _array2 = _array1; _array1 isEqualTo _array2; // true

See: isEqualRef and BIS_fnc_areEqual vs BIS_fnc_areEqualNotNil
Groups:
Variables

Syntax

Syntax:
val1 isEqualTo val2
Parameters:
val1: Anything
val2: Anything
Return Value:
Boolean

Examples

Example 1:
_arr1 = [1, [2, [3]]]; _arr2 = [1, [2, [3]]]; if (_arr1 isEqualTo _arr2) then { hint "Arrays match!" };
Example 2:
if (a isEqualTo b) then { hint "a is equal to b" }; if !(a isEqualTo b) then { hint "a is not equal to b" };

Additional Information

See also:
isNotEqualTo isEqualRef isEqualTypeAll isEqualTypeAny isEqualType isEqualTypeParams isEqualTypeArray a == b Operators

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
Tajin - c
Date unknown
Simply put, "isEqualTo" is a binary comparison. Therefor it is very fast but only accepts 100% identical matches. In some other languages this is known as "===" instead of "==".
Dedmen - c
Date unknown
When comparing with nil result is Nothing.
nil isEqualTo player;
Returns Nothing instead of expected false
diag_log [nil isEqualTo player];
Will print [bool]