a == b: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "↵↵</sqf>" to " </sqf>")
 
(79 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| ofp |= Game name
|sortKey= #


|1.00|= Game version
|game1= ofp
____________________________________________________________________________________________
|version1= 1.00


| Checks if argument <tt>a</tt> is equal to argument <tt>b</tt>. Both arguments need to be of the same [[Data Types | type]]. Comparing [[Number]]s or [[String]]s has [[SQF_syntax#Rules_of_Precedence | higher priority]] than comparing other types. String comparison is case-insensitive. If you need case-sensitive comparison use [[isEqualTo]] command. |= Description
|game2= ofpe
____________________________________________________________________________________________
|version2= 1.00


| a <nowiki>==</nowiki> b |= Syntax
|game3= arma1
|version3= 1.00


|p1 = a: [[Number]], [[String]]|=
|game4= arma2
|version4= 1.00


|p2 = b: [[Number]], [[String]]|=
|game5= arma2oa
| [[Boolean]] |= Return value
|version5= 1.50


| s2=a <nowiki>==</nowiki> b |= Syntax
|game6= tkoh
|version6= 1.00


|p21 = a: [[Group]], [[Side]], [[Object]], [[Structured Text]], [[Config]], [[Display]], [[Control]], [[Location]]|=
|game7= arma3
|version7= 0.50


|p22 = b: [[Group]], [[Side]], [[Object]], [[Structured Text]], [[Config]], [[Display]], [[Control]], [[Location]]|=
|gr1= Math
|r2= [[Boolean]] |= Return value
|gr2= Variables
____________________________________________________________________________________________


|x1 = <code>[[if]] ([[player]] <nowiki>==</nowiki> [[leader|leader]] [[group]] [[player]]) [[then]]  
|descr= Check if ''a'' is equal to ''b''. String comparison is case-'''in'''sensitive  - use [[isEqualTo]] if case sensitivity is needed.
{{Feature|important|''a'' and ''b'' types '''must''' match: comparing e.g [[String]] with [[Number]] is invalid.}}
 
|s1= a [[a == b|==]] b
 
|p1= a:
{{{!}} class="wikitable"
! Introduced in
! colspan="5" {{!}} {{GVI|ofp|1.00}}
! colspan="4" {{!}} {{GVI|arma1|1.00}}
! {{GVI|arma1|1.08}}
! colspan="3" {{!}} {{GVI|arma3|2.00}}
{{!}}-
! Possible Type
{{!}} [[Number]]
{{!}} [[Side]]
{{!}} [[String]]
{{!}} [[Object]]
{{!}} [[Group]]
{{!}} [[Structured Text]]
{{!}} [[Config]]
{{!}} [[Display]]
{{!}} [[Control]]
{{!}} [[Location]]
{{!}} [[Diary Record]]
{{!}} [[Namespace]]
{{!}} [[Boolean]]
{{!}}}
 
|p2= b: identical to ''a''<nowiki/>'s type
 
|r1= [[Boolean]]
 
|x1= <sqf>
if (player == leader group player) then
{
hint "You are the leader of your group.";
}
else
{
{
<nowiki>    </nowiki>[[hint]] "You are the leader of your group."
hint "Someone else is the boss";
} [[else]] {
};
<nowiki>    </nowiki>[[hint]] "Someone else is the boss"
</sqf>
} </code> |=


|x2 = <code>? [[name]] [[player]] <nowiki>==</nowiki> "Billy" : [[hint]] "Hello Billy, how are you?"</code> |=
|x2= <sqf>"MyRabbit" == "MYRABBIT"; // returns true</sqf>


| [[Operators]], [[isEqualTo]] |= See also
|x3= <sqf>if (alive _unit1 == alive _unit2) then { hint "Both units are either dead or both alive" };</sqf>


|seealso= [[a != b|!=]] [[Operators]] [[isEqualTo]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= ffur2007slx2_5
<!-- Note Section BEGIN -->
|timestamp= 20140415101300
<dd class="notedate">Posted on Feb 5, 2007 - 10:38
|text= For script comparison we need to detect whether scripts are running in advance, then compose both into string:
<dt class="note">'''[[User:Ceeeb|Ceeeb]]'''<dd class="note">
<sqf>if (scriptDone _var0) then [{false},{(str _var0) == (str _var1)}];</sqf>
In '''OFP v1.96''', comparison of [[String|strings]] is not case sensitive. ''Example : "STRINGtext" == "stringTEXT" returns [[true]].''
<dd class="notedate">Posted on Apr 15, 2014 - 15:34
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
(A3 1.16) for case sensitive comparison, array comparison and boolean comparison we can use [[switch do]]. e.g.
<code>
[[switch]] (_var0) [[do]] {
        [[case]] (_var1) : {[[true]]};
        [[default]] {[[false]]};
      };
</code>
For script comparison we need to detect whether scripts are running in advance, then compose both into string:
<code> [[if]] ([[scriptDone]] _var0) [[then]] [{[[false]]},{([[str]] _var0) == ([[str]] _var1)}];</code>
It is recommended to use [[isEqualTo]] for all types comparison, which is more functional and as fast as operator.
It is recommended to use [[isEqualTo]] for all types comparison, which is more functional and as fast as operator.
For multiple comparisons:
For multiple comparisons:
<code>
<sqf>
fnc_areEqual = {
fnc_areEqual = {
[[private]] ["_b","_var1","_var2"];
private ["_b", "_var1", "_var2"];
_b = [[true]];
_b = true;
[[for]] [{_i=1},{_i < ([[count]] _this) && _b},{_i=_i+1}] [[do]] {
for [{ _i = 1 }, { _i < (count _this) && _b }, { _i=_i + 1 }] do {
      _var1 = _this [[select]] (_i-1);
_var1 = _this select (_i-1);
      _var2 = _this [[select]] _i;
_var2 = _this select _i;
      [[if]] (!(_var1 [[isEqualTo]] _var2)) [[then]] {_b = [[false]];};
if (!(_var1 isEqualTo _var2)) then { _b = false; };
};
_b
};
};
_b
["A","a","a"] call fnc_areEqual; // false
};
</sqf>
["A","a","a"] [[call]] fnc_areEqual; // false
</code>
And we can use such workaround instead of using [[BIS_fnc_arrayCompare]] or [[BIS_fnc_areEqual]]
And we can use such workaround instead of using [[BIS_fnc_arrayCompare]] or [[BIS_fnc_areEqual]]
<!-- Note Section END -->
}}
 
</dl>
</dl>
<h3 style="display:none">Bottom Section</h3>
[[Category:Scripting Commands|#]]
[[Category:Scripting Commands OFP 1.99|#]]
[[Category:Scripting Commands OFP 1.96|#]]
[[Category:Scripting Commands OFP 1.46|#]]
[[Category:Scripting Commands ArmA|#]]
[[Category:Scripting Commands ArmA2|#]]
[[Category:Scripting Commands Arma 3|#]]
[[Category:Command_Group:_Math|#]]
[[Category:Command_Group:_Variables|#]]

Latest revision as of 19:48, 3 September 2024

Hover & click on the images for description

Description

Description:
Check if a is equal to b. String comparison is case-insensitive - use isEqualTo if case sensitivity is needed.
a and b types must match: comparing e.g String with Number is invalid.
Groups:
MathVariables

Syntax

Syntax:
a == b
Parameters:
a:
Introduced in Logo A0.png1.00 Logo A1 black.png1.00 Logo A1 black.png1.08 Arma 3 logo black.png2.00
Possible Type Number Side String Object Group Structured Text Config Display Control Location Diary Record Namespace Boolean
b: identical to a's type
Return Value:
Boolean

Examples

Example 1:
if (player == leader group player) then { hint "You are the leader of your group."; } else { hint "Someone else is the boss"; };
Example 2:
"MyRabbit" == "MYRABBIT"; // returns true
Example 3:
if (alive _unit1 == alive _unit2) then { hint "Both units are either dead or both alive" };

Additional Information

See also:
!= Operators isEqualTo

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
ffur2007slx2_5 - c
Posted on Apr 15, 2014 - 10:13 (UTC)
For script comparison we need to detect whether scripts are running in advance, then compose both into string:
if (scriptDone _var0) then [{false},{(str _var0) == (str _var1)}];
It is recommended to use isEqualTo for all types comparison, which is more functional and as fast as operator. For multiple comparisons:
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
And we can use such workaround instead of using BIS_fnc_arrayCompare or BIS_fnc_areEqual