selectMax: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "<dd class="note">([^}]*)<code>([^<]*)<\/code>" to "<dd class="note">$1<sqf>$2</sqf>")
m (Text replacement - "↵↵</sqf>" to " </sqf>")
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:


|descr=Returns the array element with [[max]]imum numerical value. Engine solution to [[BIS_fnc_greatestNum]] and [[BIS_fnc_findExtreme]]. Therefore it is expected that supplied array consists of [[Number]]s only. [[Boolean]]s however are also supported and will be evaluated as [[Number]]s: [[true]] - 1, [[false]] - 0.  [[nil]] value treated as 0.  
|descr=Returns the array element with [[max]]imum numerical value. Engine solution to [[BIS_fnc_greatestNum]] and [[BIS_fnc_findExtreme]]. Therefore it is expected that supplied array consists of [[Number]]s only. [[Boolean]]s however are also supported and will be evaluated as [[Number]]s: [[true]] - 1, [[false]] - 0.  [[nil]] value treated as 0.  
{{Feature | Warning | Other non [[Number]] elements (not recommended) will be evaluated as 0 and '''Bad conversion: scalar''' message will be logged into .[[rpt]].}}
{{Feature|warning|Other non [[Number]] elements (not recommended) will be evaluated as 0 and '''Bad conversion: scalar''' message will be logged into .[[rpt]].}}


|s1= [[selectMax]] array
|s1= [[selectMax]] array
Line 16: Line 16:


|x1= <sqf>_max = selectMax [1,2,3,4,5]; //5</sqf>
|x1= <sqf>_max = selectMax [1,2,3,4,5]; //5</sqf>
|x2= <sqf>// Same as, for example:  
|x2= <sqf>
// Same as, for example:  
_max = _a max _b max _c max _d;
_max = _a max _b max _c max _d;
// Only faster:
// Only faster:
_max = selectMax [_a,_b,_c,_d];</sqf>
_max = selectMax [_a,_b,_c,_d];
</sqf>


|seealso= [[selectMin]] [[min]] [[max]] [[selectRandom]] [[select]] [[selectRandomWeighted]]
|seealso= [[selectMin]] [[min]] [[max]] [[selectRandom]] [[select]] [[selectRandomWeighted]]
Line 26: Line 28:


<dt></dt>
<dt></dt>
<dd class="notedate">Posted on December 19, 2016 - 02:05 (UTC)</dd>
<dd class="notedate">Posted on 2016-12-19 - 02:05 (UTC)</dd>
<dt class="note">[[User:Longbow|Longbow]]</dt>
<dt class="note">[[User:Longbow|Longbow]]</dt>
<dd class="note">
<dd class="note">
Returns either number or boolean value, in case max value in array 0, command will return either 0 or false, which ever comes first.
Returns either number or boolean value, in case max value in array 0, command will return either 0 or false, which ever comes first.
Same for 1 and true values.
Same for 1 and true values.
<sqf>selectMax [false,0] // returns false
<sqf>
selectMax [false,0] // returns false
selectMax [0,false] // returns 0
selectMax [0,false] // returns 0
selectMax [true,1] // returns true
selectMax [true,1] // returns true
Line 37: Line 40:
</sqf>
</sqf>
in case all values are equal or less than zero, command may also return other type of values
in case all values are equal or less than zero, command may also return other type of values
<sqf>selectMax ["",false,0,-1] // returns ""
<sqf>selectMax ["",false,0,-1] // returns ""</sqf>
</sqf>
if nil value appears in array, other values are equal or less than zero, command returns nil
if nil value appears in array, other values are equal or less than zero, command returns nil
</dd>
</dd>


</dl>
</dl>

Latest revision as of 19:48, 3 September 2024

Hover & click on the images for description

Description

Description:
Returns the array element with maximum numerical value. Engine solution to BIS_fnc_greatestNum and BIS_fnc_findExtreme. Therefore it is expected that supplied array consists of Numbers only. Booleans however are also supported and will be evaluated as Numbers: true - 1, false - 0. nil value treated as 0.
Other non Number elements (not recommended) will be evaluated as 0 and Bad conversion: scalar message will be logged into .rpt.
Groups:
Arrays

Syntax

Syntax:
selectMax array
Parameters:
array: Array - array of Numbers
Return Value:
Anything - element with maximum numerical value

Examples

Example 1:
_max = selectMax [1,2,3,4,5]; //5
Example 2:
// Same as, for example: _max = _a max _b max _c max _d; // Only faster: _max = selectMax [_a,_b,_c,_d];

Additional Information

See also:
selectMin min max selectRandom select selectRandomWeighted

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
Posted on 2016-12-19 - 02:05 (UTC)
Longbow
Returns either number or boolean value, in case max value in array 0, command will return either 0 or false, which ever comes first. Same for 1 and true values.
selectMax [false,0] // returns false selectMax [0,false] // returns 0 selectMax [true,1] // returns true selectMax [1,true] // returns 1
in case all values are equal or less than zero, command may also return other type of values
selectMax ["",false,0,-1] // returns ""
if nil value appears in array, other values are equal or less than zero, command returns nil