param: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
m (Text replacement - "<sqf>([^↵][^<]*↵[^<]*)<\/sqf>" to "<sqf> $1 </sqf>")
 
(90 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma3 |= Game name
|game1= arma3
|version1= 1.48


|1.48|= Game version
|gr1= Variables


____________________________________________________________________________________________
|gr2= Arrays


| Extracts a single value with given index from input argument, similar to [[BIS_fnc_param]].  When used without argument, as shown in main syntax, internal variable [[_this]], which is usually available inside functions and event handlers, is used as argument. If input argument is not an array, it will be converted to 1 element array.
|descr= Extracts a single value with given index from input argument, similar to [[BIS_fnc_param]].  When used without argument, as shown in main syntax, internal variable [[Magic Variables#this|_this]], which is usually available inside functions and event handlers, is used as argument. If input argument is not an array, it will be converted to 1 element array.
<br><br>
<br><br>
If extracted item of input with given index is undefined, of the wrong type or of the wrong length (if the item is an array), default value is used instead. Since Arma 3 v1.53.132691, onscreen errors are displayed for when the input is of the wrong type or size.|= Description
If extracted item of input with given index is undefined, of the wrong type or of the wrong length (if the item is an array), default value is used instead. Since Arma 3 v1.54, onscreen errors are displayed for when the input is of the wrong type or size.
____________________________________________________________________________________________


| [[param]] [index, defaultValue, expectedDataTypes, expectedArrayCount] |= Syntax
|s1= [[param]] [index, defaultValue, expectedDataTypes, expectedArrayCount]


|p1= index: [[Number]] - index of required item in the input array.


|p1= [index, defaultValue, expectedDataTypes, expectedArrayCount]: [[Array]]|=
|p2= defaultValue: [[Anything]] - (Optional) a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).
|p2= index: [[Number]] - index of required item in the input array.|=
|p3= defaultValue (Optional): [[Anything]] - a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).|=
|p4= expectedDataTypes (Optional): [[Array]] of direct [[Data Types]] - checks if passed value is one of listed [[Data Types]]. If not, default value is used instead. Empty array [] means every data type is accepted.|=
|p5= expectedArrayCount (Optional): [[Number]] or [[Array]] - a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted. |=
| [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |= Return value


| s2= argument [[param]] [index, defaultValue, expectedDataTypes, expectedArrayCount] |= Syntax
|p3= expectedDataTypes: [[Array]] of direct [[:Category: Data Types| Data Types]] - (Optional) checks if passed value is one of listed [[:Category: Data Types| Data Types]]. If not, default value is used instead. Empty array [] means every data type is accepted.


|p21= argument: [[Anything]] - A usual array of params is expected. If a non-array value is passed, it will be converted to 1 element array |=
|p4= expectedArrayCount: [[Number]] or [[Array]] - (Optional) a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted.
|p22= [index, defaultValue, expectedDataTypes, expectedArrayCount]: [[Array]]|=
|p23= index: [[Number]] - index of required item in the input array.|=
|p24= defaultValue (Optional): [[Anything]] - a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).|=
|p25= expectedDataTypes (Optional): [[Array]] of direct [[Data Types]] - checks if passed value is one of listed [[Data Types]]. If not, default value is used instead. Empty array [] means every data type is accepted.|=
|p26= expectedArrayCount (Optional): [[Number]] or [[Array]] - a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted. |=
|r2= [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |= Return value
____________________________________________________________________________________________
 
|x1= <code>[1, 2, 3] [[call]] {
[[private]] ["_one", "_two", "_three"];
_one = [[param]] [0, 1];
_two = [[param]] [1, 2];
_three = [[param]] [2, 3];
// .....
};</code> |=


|x2= <code>[123] [[call]] {
|r1= [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred.
[[private]] "_val";
 
_val = [[param]] [0];
|s2= argument [[param]] [index, defaultValue, expectedDataTypes, expectedArrayCount]
};
 
|p21= argument: [[Anything]] - a usual array of params is expected. If a non-array value is passed, it will be converted to 1 element array
 
|p22= index: [[Number]] - index of required item in the input array.
 
|p23= defaultValue: [[Anything]] - (Optional) a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).
 
|p24= expectedDataTypes: [[Array]] of direct [[:Category: Data Types| Data Types]] - (Optional) checks if passed value is one of listed [[:Category: Data Types| Data Types]]. If not, default value is used instead. Empty array [] means every data type is accepted.


// Below would produce the same result as above
|p25= expectedArrayCount: [[Number]] or [[Array]] - (Optional) a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted.
123 [[call]] {
[[private]] "_val";
_val = [[param]] [0];
};</code> |=


|x3= <code>_z = [[position]] [[player]] [[param]] [2, 0];
|r2= [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred.
[[if]] (_z > 10) [[then]] {
[[hint]] "YOU ARE FLYING!";
};</code> |=


|x1= <sqf>
[1, 2, 3] call
{
private _one = param [0, 1];
private _two = param [1, 2];
private _three = param [2, 3];
// ...
};
</sqf>


|x4= <code>fnc = {
|x2= <sqf>
[[private]] ["_pos", "_rad"]
[123] call
_pos = [[param]] [0, [0,0,0], <nowiki>[</nowiki>[[objNull]], []], [2,3]];
{
_rad = [[param]] [1, 0, [0]];
private _val = param [0];
_pos [[nearObjects]] _rad;
};
};


<nowiki>[</nowiki>[[position]] [[player]], 25] [[call]] fnc; //ok
// Below would produce the same result as above
<nowiki>[</nowiki>[[player]], 25] [[call]] fnc; //ok
123 call  
[25, [[player]]] [[call]] fnc; //default values are used </code> |=
{
____________________________________________________________________________________________
private _val = param [0];
};
</sqf>


| [[params]], [[select]], [[set]], [[resize]], [[reverse]], [[in]], [[find]], [[toArray]], [[toString]], [[forEach]], [[count]], [[deleteAt]], [[deleteRange]], [[append]], [[sort]], [[arrayIntersect]], [[splitString]], [[joinString]], [[isEqualTypeAll]], [[isEqualType]], [[isEqualTypeParams]], [[isEqualTypeArray]], [[isEqualTypeAny]], [[typeName]], [[BIS_fnc_param]] |= See also
|x3= <sqf>
_z = position player param [2, 0];
if (_z > 10) then
{
hint "YOU ARE FLYING!";
};
</sqf>


}}
|x4= <sqf>
fnc =
{
private _pos = param [0, [0,0,0], [objNull, []], [2,3]];
private _rad = param [1, 0, [0]];
_pos nearObjects _rad;
};


[[Category:Scripting_Commands_Arma_3]]
[position player, 25] call fnc; // ok
[[Category:Arma_3:_New_Scripting_Commands_List]]
[player, 25] call fnc; // ok
[[Category:Command_Group:_Variables|{{uc:{{PAGENAME}}}}]]
[25, player] call fnc; // default values are used
</sqf>


<!-- CONTINUE Notes -->
|seealso= [[params]] [[select]] [[set]] [[resize]] [[reverse]] [[in]] [[find]] [[findIf]] [[toArray]] [[toString]] [[forEach]] [[count]] [[deleteAt]] [[deleteRange]] [[append]] [[sort]] [[arrayIntersect]] [[splitString]] [[joinString]] [[isEqualTypeAll]] [[isEqualType]] [[isEqualTypeParams]] [[isEqualTypeArray]] [[isEqualTypeAny]] [[typeName]] [[BIS_fnc_param]]
<dl class="command_description">
}}
<dd class="notedate">Posted on November 27, 2015 - 21:18 (UTC)</dd>
<dt class="note">[[User:Commy2|Commy2]]</dt>
<dd class="note">
Be careful when using the default value combined with the find command.<br>
A negative index between -1.4999999 and 0 will still pick the first element of the array instead of the default value.<br>
<code>
["one","two","three"] param [([1,2,3] find 5),"not found"]
["one","two","three"] param [       -1      ,"not found"]
-> "one"
</code>
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 19:42, 3 September 2024

Hover & click on the images for description

Description

Description:
Extracts a single value with given index from input argument, similar to BIS_fnc_param. When used without argument, as shown in main syntax, internal variable _this, which is usually available inside functions and event handlers, is used as argument. If input argument is not an array, it will be converted to 1 element array.

If extracted item of input with given index is undefined, of the wrong type or of the wrong length (if the item is an array), default value is used instead. Since Arma 3 v1.54, onscreen errors are displayed for when the input is of the wrong type or size.
Groups:
VariablesArrays

Syntax

Syntax:
param [index, defaultValue, expectedDataTypes, expectedArrayCount]
Parameters:
index: Number - index of required item in the input array.
defaultValue: Anything - (Optional) a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).
expectedDataTypes: Array of direct Data Types - (Optional) checks if passed value is one of listed Data Types. If not, default value is used instead. Empty array [] means every data type is accepted.
expectedArrayCount: Number or Array - (Optional) a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted.
Return Value:
Anything - extracted value on success or default value otherwise. Nothing if syntax error occurred.

Alternative Syntax

Syntax:
argument param [index, defaultValue, expectedDataTypes, expectedArrayCount]
Parameters:
argument: Anything - a usual array of params is expected. If a non-array value is passed, it will be converted to 1 element array
index: Number - index of required item in the input array.
defaultValue: Anything - (Optional) a default value to return if input is undefined, of the wrong type or of the wrong length (if the item is an array).
expectedDataTypes: Array of direct Data Types - (Optional) checks if passed value is one of listed Data Types. If not, default value is used instead. Empty array [] means every data type is accepted.
expectedArrayCount: Number or Array - (Optional) a single size or array of sizes. If passed input value is an array, checks that it has a certain number of elements. If not, default value is used instead. Empty array [] means any size is accepted.
Return Value:
Anything - extracted value on success or default value otherwise. Nothing if syntax error occurred.

Examples

Example 1:
[1, 2, 3] call { private _one = param [0, 1]; private _two = param [1, 2]; private _three = param [2, 3]; // ... };
Example 2:
[123] call { private _val = param [0]; }; // Below would produce the same result as above 123 call { private _val = param [0]; };
Example 3:
_z = position player param [2, 0]; if (_z > 10) then { hint "YOU ARE FLYING!"; };
Example 4:
fnc = { private _pos = param [0, [0,0,0], [objNull, []], [2,3]]; private _rad = param [1, 0, [0]]; _pos nearObjects _rad; }; [position player, 25] call fnc; // ok [player, 25] call fnc; // ok [25, player] call fnc; // default values are used

Additional Information

See also:
params select set resize reverse in find findIf toArray toString forEach count deleteAt deleteRange append sort arrayIntersect splitString joinString isEqualTypeAll isEqualType isEqualTypeParams isEqualTypeArray isEqualTypeAny typeName BIS_fnc_param

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