a hash b: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Bot: Reverted to revision 109301 by killzone_kid on 2018-10-02T17:22:19Z)
m (Some wiki formatting)
 
(56 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Command|Comments=
{{RV|type=command
____________________________________________________________________________________________


| arma3 |Game name=
|sortKey= #


|1.82|Game version=
|game1= arma3
____________________________________________________________________________________________
|version1= 1.82


| Selects an element from an [[Array | array]], same as [[select]] command for arrays, but has [[SQF_syntax#Rules_of_Precedence | higher precedence]] |Description=
|gr1= Variables
____________________________________________________________________________________________


| array  [[a_hash_b|#]] index |Syntax=
|descr= Selects an element from an [[Array]], same as [[select]] command for arrays, but has [[Order of Precedence|higher precedence]].
{{Feature|informative|'''#''' has higher precedence than all binary operators, but it has lower precedence than unary operators (see {{Link|#Example 3}}).}}


| p1= array: [[Array]] |Parameter 1=
|s1= array [[a_hash_b|#]] index


| p2= index: [[Number]] |Parameter 2=
|p1= array: [[Array]]


| [[Anything]] |Return value=
|p2= index: [[Number]]
____________________________________________________________________________________________
 
 
|x1= <code>[1,2,3,4] [[a_hash_b|#]] 2; {{codecomment|// result is 3}}</code> |Example 1=


|x2= <code>[[position]] [[player]] [[a_hash_b|#]] 2; {{codecomment|// result is Z coordinate of player's position}}</code> |Example 2=
|r1= [[Anything]]
____________________________________________________________________________________________


| [[select]], [[selectRandom]], [[selectRandomWeighted]], [[set]], [[resize]], [[reverse]], [[in]], [[find]], [[toArray]], [[toString]], [[forEach]], [[count]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[param]], [[params]], [[splitString]], [[joinString]], [[pushBack]], [[pushBackUnique]], [[apply]] |See also=
|x1= <sqf>[1, 2, 3, 4] # 2; // result is 3</sqf>
 
|x2= <sqf>getPosASL player # 2; // result is Z component of player's position</sqf>
 
|x3= <sqf>
//'getPosASL' is unary; '#' and '+' are binary; precedence is: 'getPosASL' > '#' > '+'
getPosASL player # 2 + 1; // equivalent to (getPosASL player # 2) + 1, not (getPosASL player)#(2+1)
</sqf>
 
|seealso= [[select]] [[selectRandom]] [[selectRandomWeighted]] [[set]] [[resize]] [[reverse]] [[in]] [[find]] [[toArray]] [[toString]] [[forEach]] [[count]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[param]] [[params]] [[splitString]] [[joinString]] [[pushBack]] [[pushBackUnique]] [[apply]]
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= KC Grimes
|timestamp= 20180425005100
|text= Although not alternative syntax, the below notations work as expected:
<sqf>
["A", "B", "C"] # 1; // B
["A", "B", "C"] #1; // B
["A", "B", "C"]#1; // B
["A", "B", ["C", "D"]]#2#0; // C
</sqf>
}}


<h3 style="display:none">Bottom Section</h3>
{{Note
[[Category:Scripting Commands|#]]
|user= 7erra
[[Category:Scripting Commands Arma 3|#]]
|timestamp= 20190503154100
|text= Here is an example of what higher precedence means:
<sqf>
[1, 2, 3, 4] select 2 / 2; // divides 2 with 2, therefore selects the second element at index 1, result = 2
[1, 2, 3, 4] select (2 / 2); // same result with brackets
[1, 2, 3, 4] # 2 / 2; // selects third element, then divides by 2 = 1.5
([1, 2, 3, 4] # 2) / 2; // same result with brackets
</sqf>
<br>
This operator can not be used in conjunction with the #define preprocessor.<br>
<sqf>
#define SEL_ERR [0,1,2]#0; // error
#define SEL_NOERR [0,1,2] select 0; // works
</sqf>
}}


<!-- CONTINUE Notes -->
{{Note
<dl class="command_description">
|user= Fett_li
<dd class="notedate">Posted on April 25, 2018 - 00:51 (UTC)</dd>
|timestamp= 20210402161800
<dt class="note">[[User:KC Grimes|KC Grimes]]</dt>
|text= Beware new-lines when using this operator. I suspect the preprocessor to fail. The following code will not compile without throwing an error:
<dd class="note">
<sqf>
Although not alternative syntax, the below notations work as expected:
[0]
<code>["A","B","C"] # 1; //B
# 0;
["A","B","C"] #1; //B
</sqf>
["A","B","C"]#1; //B
}}
["A","B",["C","D"]]#2#0; //C</code>
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 19:08, 15 March 2024

Hover & click on the images for description

Description

Description:
Selects an element from an Array, same as select command for arrays, but has higher precedence.
# has higher precedence than all binary operators, but it has lower precedence than unary operators (see Example 3).
Groups:
Variables

Syntax

Syntax:
array # index
Parameters:
array: Array
index: Number
Return Value:
Anything

Examples

Example 1:
[1, 2, 3, 4] # 2; // result is 3
Example 2:
getPosASL player # 2; // result is Z component of player's position
Example 3:
//'getPosASL' is unary; '#' and '+' are binary; precedence is: 'getPosASL' > '#' > '+' getPosASL player # 2 + 1; // equivalent to (getPosASL player # 2) + 1, not (getPosASL player)#(2+1)

Additional Information

See also:
select selectRandom selectRandomWeighted set resize reverse in find toArray toString forEach count deleteAt deleteRange append sort param params splitString joinString pushBack pushBackUnique apply

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
KC Grimes - c
Posted on Apr 25, 2018 - 00:51 (UTC)
Although not alternative syntax, the below notations work as expected:
["A", "B", "C"] # 1; // B ["A", "B", "C"] #1; // B ["A", "B", "C"]#1; // B ["A", "B", ["C", "D"]]#2#0; // C
7erra - c
Posted on May 03, 2019 - 15:41 (UTC)
Here is an example of what higher precedence means:
[1, 2, 3, 4] select 2 / 2; // divides 2 with 2, therefore selects the second element at index 1, result = 2 [1, 2, 3, 4] select (2 / 2); // same result with brackets [1, 2, 3, 4] # 2 / 2; // selects third element, then divides by 2 = 1.5 ([1, 2, 3, 4] # 2) / 2; // same result with brackets

This operator can not be used in conjunction with the #define preprocessor.
#define SEL_ERR [0,1,2]#0; // error #define SEL_NOERR [0,1,2] select 0; // works
Fett_li - c
Posted on Apr 02, 2021 - 16:18 (UTC)
Beware new-lines when using this operator. I suspect the preprocessor to fail. The following code will not compile without throwing an error:
[0] # 0;