param: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "|= |x2=" to "|Example1= |x2=")
Line 19: Line 19:
|p2= index: [[Number]] - index of required item in the input array.|Parameter2=
|p2= index: [[Number]] - index of required item in the input array.|Parameter2=


|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).|=
|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). |Parameter3=
|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.|=
|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.|Parameter4=
|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. |=
|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. |Parameter5=
| [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |RETURNVALUE=
| [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |RETURNVALUE=


Line 28: Line 28:
|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 |PARAMETER21=
|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 |PARAMETER21=


|p22= [index, defaultValue, expectedDataTypes, expectedArrayCount]: [[Array]]|=
|p22= [index, defaultValue, expectedDataTypes, expectedArrayCount]: [[Array]] |Parameter22=
|p23= index: [[Number]] - index of required item in the input array.|=
|p23= index: [[Number]] - index of required item in the input array.|Parameter23=
|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).|=
|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).|Parameter24=
|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.|=
|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.|Parameter25=
|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. |=
|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. |Parameter26=
|r2= [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |RETURNVALUE=
|r2= [[Anything]] - extracted value on success or default value otherwise. [[Nothing]] if syntax error occurred. |RETURNVALUE2=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
Line 41: Line 41:
[[private]] _two = [[param]] [1, 2];
[[private]] _two = [[param]] [1, 2];
[[private]] _three = [[param]] [2, 3];
[[private]] _three = [[param]] [2, 3];
// .....
{{cc|...}}
};</code> |Example1=
};</code> |Example1=


Line 49: Line 49:
};
};


// Below would produce the same result as above
{{cc|Below would produce the same result as above}}
123 [[call]]  
123 [[call]]  
{
{
Line 59: Line 59:
{
{
[[hint]] "YOU ARE FLYING!";
[[hint]] "YOU ARE FLYING!";
};</code> |=
};</code> |Example3=




Line 69: Line 69:
};
};


<nowiki>[</nowiki>[[position]] [[player]], 25] [[call]] fnc; //ok
[<nowiki/>[[position]] [[player]], 25] [[call]] fnc; {{cc|ok}}
<nowiki>[</nowiki>[[player]], 25] [[call]] fnc; //ok
[<nowiki/>[[player]], 25] [[call]] fnc; {{cc|ok}}
[25, [[player]]] [[call]] fnc; //default values are used </code> |=
[25, [[player]]] [[call]] fnc; {{cc|default values are used}}</code> |Example4=
____________________________________________________________________________________________
____________________________________________________________________________________________


| [[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]] |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]] |SEEALSO=
}}
}}



Revision as of 20:14, 19 December 2019

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.53.132691, onscreen errors are displayed for when the input is of the wrong type or size.
Groups:
Uncategorised

Syntax

Syntax:
param [index, defaultValue, expectedDataTypes, expectedArrayCount]
Parameters:
[index, defaultValue, expectedDataTypes, expectedArrayCount]: Array
index: Number - index of required item in the input array.
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).
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.
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.
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, defaultValue, expectedDataTypes, expectedArrayCount]: Array
index: Number - index of required item in the input array.
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).
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.
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.
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:
paramsselectsetresizereverseinfindfindIftoArraytoStringforEachcountdeleteAtdeleteRangeappendsortarrayIntersectsplitStringjoinStringisEqualTypeAllisEqualTypeisEqualTypeParamsisEqualTypeArrayisEqualTypeAnytypeNameBIS_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

Notes

Bottom Section

Posted on November 8, 2016 - 07:50 (UTC)
Demellion
You can also use param in a complex with another commands. For example call, compile and format: ["var = 2"] call { call compile format ["%1", param [0,"",[""]]]; // compiled param string value hint str (var); // 2 };