a - b: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Removed one bracket ])
(updated description.example, moved malformatted note to talk)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| For numbers: '''a''' minus '''b'''. |= Description
| Subtracts '''b''' from '''a'''. '''a''' and '''b''' need to be of the same type, both [[Number]]s or both [[Array]]s. In Arma 3 it is possible to subtract nested arrays. |= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| a '''-''' b |= Syntax
| a '''-''' b |= Syntax


|p1 = a: [[Number]] or [[Array]]
|p1 = a: [[Number]] or [[Array]]
Line 19: Line 18:
| [[Number]] or [[Array]]  |= Return value
| [[Number]] or [[Array]]  |= Return value
____________________________________________________________________________________________
____________________________________________________________________________________________
|x1 = <code>[[Number]]<br>_sum <nowiki>=</nowiki> 10 '''-''' 7 </code>
|x1 = For numbers: <code>_sum = 10 - 7; //_sum is 3</code>|=
Result: _sum is 3
 
|x2 = For arrays: contents of array '''b''' removed from array '''a'''<code>_result = [1, 2, 2, [[player]], "String"] - [2, [[player]], [[player]], "String"]; //_result is [1]</code>|=
 
|x3 = Compare:<code>[0,[0],<nowiki>[</nowiki>[0]]] - [0]; //<nowiki>[</nowiki>[0],<nowiki>[</nowiki>[0]]]
[0,[0],<nowiki>[</nowiki>[0]]] - <nowiki>[</nowiki>[0]]; //[0,<nowiki>[</nowiki>[0]]] - Arma 3 only
[0,[0],<nowiki>[</nowiki>[0]]] - <nowiki>[</nowiki><nowiki>[</nowiki>[0]]]; //[0,[0]] - Arma 3 only</code>|=


|x2 = <code> For arrays: Contents of array '''b''' removed from array '''a'''.<br>[[Array]]<br>_result <nowiki>=</nowiki> [1,2,2,[[player]],"String"] '''-''' [2,[[player]],[[player]],"String"] </code>
_result is [1]
| [[Array]], [[Operators]] |= See also
| [[Array]], [[Operators]] |= See also


Line 31: Line 33:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
Note that this way of removing elements from an array will not work if those elements are themselves arrays.
Example:
[[0,0,0],[1,1,1],[2,2,2] ] - [1,1,1]
Will not remove the element [1,1,1] from the first array.
A more practical example:
[ [[getPos]] unit1, [[getPos]] unit2, [[getPos]] unit3] - [[getPos]] unit3
Will not remove the position of unit3 from the first array.


<!-- Note Section END -->
<!-- Note Section END -->
Line 50: Line 38:


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>




Line 65: Line 50:
[[Category:Command_Group:_Variables|#]]
[[Category:Command_Group:_Variables|#]]
[[Category:Notes: Improper Formatting|{{uc:{{PAGENAME}}}}]]
[[Category:Notes: Improper Formatting|{{uc:{{PAGENAME}}}}]]
{{subst:Add new note/construct|This will work if you do: <code>[[3,3,3],[1,1,1],[5,5,5]] - [[1,1,1] ] //Return: [[3,3,3],[5,5,5]]</code>
You have to cover it in extra brackets, because you want to remove the whole element.
Not: <code>[[3,3,3],[1,1,1],[5,5,5]] - [1,1,1] //Return: [[3,3,3],[1,1,1],[5,5,5]]</code>
But this would work again: <code>[[3,3,3],-1,-1,-1,[5,5,5]] - [1,1,1] //Return: [[3,3,3],[5,5,5]]</code>
Note, that all elements found will be removed: <code>[1,2,3,2,4,3,5,2,6,2,7,2] - [2] //Return: [1,3,4,5,6,7]</code>}}

Revision as of 00:57, 16 August 2016

Hover & click on the images for description

Description

Description:
Subtracts b from a. a and b need to be of the same type, both Numbers or both Arrays. In Arma 3 it is possible to subtract nested arrays.
Groups:
Uncategorised

Syntax

Syntax:
a - b
Parameters:
a: Number or Array
b: Number or Array
Return Value:
Number or Array

Examples

Example 1:
For numbers: _sum = 10 - 7; //_sum is 3
Example 2:
For arrays: contents of array b removed from array a_result = [1, 2, 2, player, "String"] - [2, player, player, "String"]; //_result is [1]
Example 3:
Compare:[0,[0],[[0]]] - [0]; //[[0],[[0]]] [0,[0],[[0]]] - [[0]]; //[0,[[0]]] - Arma 3 only [0,[0],[[0]]] - [[[0]]]; //[0,[0]] - Arma 3 only

Additional Information

See also:
ArrayOperators

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

Notes

Bottom Section