a hash b: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) |
Lou Montana (talk | contribs) m (Some wiki formatting) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
|gr1= Variables | |gr1= Variables | ||
|descr= Selects an element from an [[Array | |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}}).}} | |||
|s1= array [[a_hash_b|#]] index | |s1= array [[a_hash_b|#]] index | ||
Line 18: | Line 19: | ||
|r1= [[Anything]] | |r1= [[Anything]] | ||
|x1= < | |x1= <sqf>[1, 2, 3, 4] # 2; // result is 3</sqf> | ||
|x2= < | |x2= <sqf>getPosASL player # 2; // result is Z component of player's position</sqf> | ||
|seealso= [[select]] [[selectRandom]] [[selectRandomWeighted]] [[set]] [[resize]] [[reverse]] [[in]] [[find]] [[toArray]] [[toString]] [[forEach]] [[count]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[param]] [[params]] [[splitString]] [[joinString]] [[pushBack]] | |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]] | |||
}} | }} | ||
{{Note | |||
|user= KC Grimes | |||
|timestamp= 20180425005100 | |||
|text= Although not alternative syntax, the below notations work as expected: | |||
<sqf> | |||
["A", "B", "C"] # 1; // B | |||
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 | ||
["A","B","C"]#1; //B | </sqf> | ||
["A","B",["C","D"]]#2#0; //C</ | }} | ||
{{Note | |||
|user= 7erra | |||
|timestamp= 20190503154100 | |||
|text= Here is an example of what higher precedence means: | |||
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] | [1, 2, 3, 4] select (2 / 2); // same result with brackets | ||
[1,2,3,4] # 2/2; | [1, 2, 3, 4] # 2 / 2; // selects third element, then divides by 2 = 1.5 | ||
([1,2,3,4] # 2)/2; | ([1, 2, 3, 4] # 2) / 2; // same result with brackets | ||
</ | </sqf> | ||
<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> | ||
< | <sqf> | ||
#define SEL_NOERR [0,1,2] select 0 //works</ | #define SEL_ERR [0,1,2]#0; // error | ||
#define SEL_NOERR [0,1,2] select 0; // works | |||
</sqf> | |||
}} | |||
{{Note | |||
|user= Fett_li | |||
|timestamp= 20210402161800 | |||
|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: | <sqf> | ||
< | [0] | ||
# 0; | # 0; | ||
</ | </sqf> | ||
}} | |||
Latest revision as of 21:29, 2 September 2024
Description
- Description:
- Selects an element from an Array, same as select command for arrays, but has higher precedence.
- Groups:
- Variables
Syntax
Examples
- Example 1:
- [1, 2, 3, 4] # 2; // result is 3
- Example 2:
- Example 3:
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
- 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
- Posted on May 03, 2019 - 15:41 (UTC)
-
Here is an example of what higher precedence means:
This operator can not be used in conjunction with the #define preprocessor.
- 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;