a = b: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "numbers" to "Numbers")
 
(99 intermediate revisions by 18 users not shown)
Line 1: Line 1:
[[Category:Scripting Commands]]
{{RV|type=command
[[Category:Scripting Commands OFP 1.97]]
[[Category:Scripting Commands OFP 1.46]]
[[Category:Scripting Commands ArmA]]


back to [[Scripting_Reference#.23|COMREF]]
|sortKey= #


<h2 style="color:#000066">''' ''a'' = ''b'' '''</h2>
|game1= ofp
|version1= 1.00


|game2= ofpe
|version2= 1.00


'''Operand types:'''
|game3= arma1
|version3= 1.00


'''a:''' [[Number]], [[Group]], [[String]] or [[Object]]
|game4= arma2
|version4= 1.00


'''b:''' [[Number]], [[Group]], [[String]] or [[Object]]
|game5= arma2oa
|version5= 1.50


'''Type of returned value:'''
|game6= tkoh
|version6= 1.00


[[Nothing]]
|game7= arma3
|version7= 0.50


'''Description:'''
|gr1= Variables


a '''is equal to''' b  
|descr= Assigns the result of expression on the right to the variable on the left. Technically this is not a command and it is not listed in [[supportInfo]]; this is more of a compiler instruction.
{{Feature|important|The following structure is invalid: <sqf inline>a = b = c = 4;</sqf>.}}


|s1= variable [[a = b|=]] value


'''Example:'''
|p1= variable: [[Anything]] - see [[Identifier]]


_value '''=''' 5
|p2= value: [[Anything]]


_mygroup '''=''' [[group]] [[player]]
|r1= [[Nothing]] {{Feature|important|The returned value is not equivalent to [[nil]]. See {{Link|#Notes}} below for additional information.}}


_greeting '''=''' "Hello!"
|x1= <sqf>_value = 5;</sqf>


_enemytank '''=''' mytank1
|x2= <sqf>_mygroup = group player;</sqf>
 
|x3= <sqf>_greeting = "Hello!";</sqf>
 
|x4= <sqf>private _enemyTank = myTank1;</sqf>
 
|seealso= [[Operators]]
}}
 
{{Note
|user= Kronzky
|timestamp= 20061215052700
|text= A conditional assignment can be done via the following syntax:
<sqf>_msg = if (alive player) then {"you're alive"} else {"you're dead"}</sqf>
}}
 
{{Note
|user= Alef
|timestamp= 20090622162700
|text= It's possible to assign to [[Number]]s. Numbers values are not changed. Useful instead of assigning to ''nul'' or ''nil'' when a result is of no use.
<sqf>[player] execVM "myScript.sqf"</sqf>
}}
 
{{Note
|user= Dedmen
|timestamp= 20161109002900
|text= This operator actually does not return a Nil. It really returns pure Nothing. Not Nil Nothing.<br>
This can cause problems. For example:
<sqf>
_var1 = call {
_var2 = "";
};
</sqf>
The return value of the "call" is the return value of the "{{=}}" operator.<br>
If it were a nil then of cause "_var {{=}} nil;" would work just fine.<br>
But in reality this causes a "Generic Error in expression" because you can't assign pure Nothing to anything
}}

Latest revision as of 14:49, 8 November 2023

Hover & click on the images for description

Description

Description:
Assigns the result of expression on the right to the variable on the left. Technically this is not a command and it is not listed in supportInfo; this is more of a compiler instruction.
The following structure is invalid: a = b = c = 4;.
Groups:
Variables

Syntax

Syntax:
variable = value
Parameters:
variable: Anything - see Identifier
value: Anything
Return Value:
Nothing
The returned value is not equivalent to nil. See Notes below for additional information.

Examples

Example 1:
_value = 5;
Example 2:
_mygroup = group player;
Example 3:
_greeting = "Hello!";
Example 4:
private _enemyTank = myTank1;

Additional Information

See also:
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
Kronzky - c
Posted on Dec 15, 2006 - 05:27 (UTC)
A conditional assignment can be done via the following syntax:
_msg = if (alive player) then {"you're alive"} else {"you're dead"}
Alef - c
Posted on Jun 22, 2009 - 16:27 (UTC)
It's possible to assign to Numbers. Numbers values are not changed. Useful instead of assigning to nul or nil when a result is of no use.
[player] execVM "myScript.sqf"
Dedmen - c
Posted on Nov 09, 2016 - 00:29 (UTC)
This operator actually does not return a Nil. It really returns pure Nothing. Not Nil Nothing.
This can cause problems. For example:
_var1 = call { _var2 = ""; };
The return value of the "call" is the return value of the "=" operator.
If it were a nil then of cause "_var = nil;" would work just fine.
But in reality this causes a "Generic Error in expression" because you can't assign pure Nothing to anything