a hash b: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Some wiki formatting)
Line 18: Line 18:
|r1= [[Anything]]
|r1= [[Anything]]


|x1= <code>[1,2,3,4] [[a_hash_b|#]] 2; {{cc|result is 3}}</code>
|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>
|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' > '#' > '+'
|x3= <sqf>
getPosASL player # 2 + 1; // equivalent to (getPosASL player # 2) + 1, not (getPosASL player)#(2+1)</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]]
|seealso= [[select]] [[selectRandom]] [[selectRandomWeighted]] [[set]] [[resize]] [[reverse]] [[in]] [[find]] [[toArray]] [[toString]] [[forEach]] [[count]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[param]] [[params]] [[splitString]] [[joinString]] [[pushBack]] [[pushBackUnique]] [[apply]]
}}
}}


<dl class="command_description">
{{Note
|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>
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on April 25, 2018 - 00:51 (UTC)</dd>
|user= 7erra
<dt class="note">[[User:KC Grimes|KC Grimes]]</dt>
|timestamp= 20190503154100
<dd class="note">
|text= Here is an example of what higher precedence means:
Although not alternative syntax, the below notations work as expected:
<sqf>
<code>["A","B","C"] # 1; //B
[1,2,3,4] [[select]] 2/2; // divides 2 with 2, therefore selects second element = 2
["A","B","C"] #1; //B
[1,2,3,4] [[select]] (2/2); // same result with brackets
["A","B","C"]#1; //B
[1,2,3,4] # 2/2; // selects third element, then divides by 2 = 1.5
["A","B",["C","D"]]#2#0; //C</code>
([1,2,3,4] # 2)/2; // same result with brackets
</dd>
</sqf>
 
<dt><dt>
<dd class="notedate">Posted on May 3, 2019 - 15:41 (UTC)</dd>
<dt class="note">[[User:7erra|7erra]]</dt>
<dd class="note">
Here is an example of what higher precedence means:
<code>[1,2,3,4] [[select]] 2/2;   // divides 2 with 2, therefore selects second element = 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
</code>
<br>
<br>
This operator can not be used in conjunction with the #define preprocessor.<br>
This operator can not be used in conjunction with the #define preprocessor.<br>
<code><nowiki>#define SEL_ERR [0,1,2]#0 //error
<sqf>
#define SEL_NOERR [0,1,2] select 0 //works</nowiki></code>
#define SEL_ERR [0,1,2]#0; // error
</dd>
#define SEL_NOERR [0,1,2] select 0; // works
</sqf>
}}


<dt></dt>
{{Note
<dd class="notedate">Posted on April 2, 2021 - 16:18 (UTC)</dd>
|user= Fett_li
<dt class="note">[[User:fett_li|fett_li]]</dt>
|timestamp= 20210402161800
<dd class="note">
|text= Beware new-lines when using this operator. I suspect the preprocessor to fail. The following code will not compile without throwing an error:
Beware new-lines when using this operator. I suspect the preprocessor to fail. The following code will not compile without throwing an error:
<code><nowiki>[0]
<code><nowiki>[0]
# 0;
# 0;
</nowiki></code>
</nowiki></code>
</dd>
}}
 
</dl>

Revision as of 23:39, 3 May 2022

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 second element = 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;