params: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(wip)
 
(examples)
Line 8: Line 8:


| Parses array of params into array of private variables. When used without argument, as shown in syntax 1, internal variable "_this", which is usually available inside functions and event handlers, is used as argument.  
| Parses array of params into array of private variables. When used without argument, as shown in syntax 1, internal variable "_this", which is usually available inside functions and event handlers, is used as argument.  
<br>The values of passed argument array would be assigned to private variables given in the format array respectful of their order in the array. It is also possible to skip some values by giving empty string for a private variable name in format array.<br>
<br>The values of passed argument array would be assigned to private variables given in the format array and respectful of their order in the array. To skip some values, give an empty string for a private variable name in format array.<br>
To force variable value to a predefined value when [[nil]] is passed, use format for the private variable which is similar to [[getVariable]] <array> syntax, [variableName, defaultValue].<br>
To force variable value to a predefined value when argument is undefined, use [variableName, defaultValue] format. To make sure passed value is of a specific type, supply the desired [[typeName]] in addition. The command will throw an error and return [[false]] if validation fails. For "ARRAY" types it is also possible to validate the length of the passed array.<br>
To make sure passed value is of a given type, supply the desired [[typeName]]. The command will throw an error and return [[false]] if validation fails. For "ARRAY" types it is also possible to validate the length of the passed array.<br>
On successful parsing [[params]] returns [[true]]  
On successful parsing [[params]] returns [[true]]  
|= Description
|= Description
Line 48: Line 47:
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>[1,2,3] [[call]] {
|x1= <code>[1, 2, 3] [[call]] {
[[private]] ["_one","_two","_three"];
[[private]] ["_one", "_two", "_three"];
_one = _this [[select]] 0;
_one = _this [[select]] 0;
_two = _this [[select]] 1;
_two = _this [[select]] 1;
_three = _this [[select]] 2;
_three = _this [[select]] 2;
.....
// .....
};
};


// same as above using params
// Same as above, only using params
[1,2,3] [[call]] {
[1, 2, 3] [[call]] {
[[params]] ["_one","_two","_three"];
[[params]] ["_one", "_two", "_three"];
.....
// .....
};</code> |=
};</code> |=


Line 66: Line 65:
};
};


// below would produce the same result as above
// Below would produce the same result as above
123 [[call]] {
123 [[call]] {
[[params]] ["_myvar"];
[[params]] ["_myvar"];
};</code> |=
};</code> |=


|x3= <code>[[position]] [[player]] [[params]] ["","","_z"];
|x3= <code>[[position]] [[player]] [[params]] ["", "", "_z"];
[[if]] (_z > 10) [[then]] {
[[if]] (_z > 10) [[then]] {
[[hint]] "YOU ARE FLYING!";
[[hint]] "YOU ARE FLYING!";
};</code> |=
};</code> |=


|x4= <code>[1,[[nil]],2] [[params]] ["_var1","_var2","_var3"];
|x4= <code>[1, [[nil]], 2] [[params]] ["_var1", "_var2", "_var3"];
// all 3 variables are made private
// All 3 variables are made private but only _var1 and _var3 are defined
// but only _var1 and _var3 are defined


[1,[[nil]],2] [[params]] ["_var1",["_var2",23],"_var3"];
[1, [[nil]], 2] [[params]] ["_var1", ["_var2", 23], "_var3"];
// all 3 variables are private and defined</code> |=
// All 3 variables are private and defined</code> |=


|x5= <code>[1,2] [[call]] {
|x5= <code>[1, 2] [[call]] {
[[if]] (![[params]] ["_var1","_var2",["_var3",[[true]],[[typeName]] [[true]]]]) [[exitwith]] {};
[[if]] (![[params]] ["_var1", "_var2", ["_var3", [[true]], [[typeName]] [[true]]]]) [[exitWith]] {};
[[hint]] [[str]] [_var1,_var2,_var3];
[[hint]] [[str]] [_var1, _var2, _var3];
};
};
// The hint shows [1,2,true]
// The hint shows [1,2,true]


[1,2,3] [[call]] {
[1, 2, 3] [[call]] {
[[if]] (![[params]] ["_var1","_var2",["_var3",[[true]],"BOOL"]]) [[exitwith]] {};
[[if]] (![[params]] ["_var1", "_var2", ["_var3", [[true]], "BOOL"]]) [[exitWith]] {};
[[hint]] [[str]] [_var1,_var2,_var3];
[[hint]] [[str]] [_var1, _var2, _var3];
};
};
// Error! Type Number, expected BOOL</code> |=
// Error! Type Number, expected BOOL</code> |=


|x6= <code></code> |=
|x6= <code>[1, "ok", [1, 2, 3]] [[call]] {
|x7= <code</code> |=
[[if]] (![[params]] [
|x8= <code></code> |=
["_var1", 0, "SCALAR"],
|x9= <code></code> |=
["_var2", "", [[typeName]] ""],
|x10= <code></code> |=
["_var3", [0,0,0], "ARRAY", 3]
]) [[exitWith]] {};
[[hint]] "ok";
};
// Passes validation
 
[1, 2, [3, 4, 5]] [[call]] {
[[if]] (![[params]] ["_var1", "_var2", ["_var3", [], [[typeName]] [], 0]]) [[exitWith]] {};
[[hint]] "ok";
};
// Fails, because passed array is expected to be of 0 length, i.e. empty</code> |=
|x7= <code>[[position]] [[player]] [[params]] ["_x", "_y"];
[[player]] [[setPos]] [_x, _y, 100];</code> |=
|x8= <code>[1, 2, 3, [4, 5, 6]] [[call]] {
[[params]] ["_one", "_two", "_three"];
_this [[select]] 3 [[params]] ["_four", "_five", "_six"];
};</code> |=
|x9= <code>{
_x [[params]] ["_group", "_index"];
// .....
} [[forEach]] [[waypoints]] [[group]] [[player]];</code> |=
|x10= <code>fn_someFnc = {
[[params]] ["_position", ["_direction", 0], ["_name", ""]];
// Extract the x, y, and z from "_position" array:
_position [[params]] ["_x", "_y", "_z"];
// .....
};
 
<nowiki>[</nowiki>[[position]] [[player]], [[direction]] [[player]], [[name]] [[player]]] [[call]] fn_someFnc;</code> |=


____________________________________________________________________________________________
____________________________________________________________________________________________

Revision as of 21:24, 1 June 2015

-wrong parameter ("arma3dev") defined!-[[:Category:Introduced with arma3dev version 1.45|1.45]]
Hover & click on the images for description

Description

Description:
Parses array of params into array of private variables. When used without argument, as shown in syntax 1, internal variable "_this", which is usually available inside functions and event handlers, is used as argument.
The values of passed argument array would be assigned to private variables given in the format array and respectful of their order in the array. To skip some values, give an empty string for a private variable name in format array.
To force variable value to a predefined value when argument is undefined, use [variableName, defaultValue] format. To make sure passed value is of a specific type, supply the desired typeName in addition. The command will throw an error and return false if validation fails. For "ARRAY" types it is also possible to validate the length of the passed array.
On successful parsing params returns true
Groups:
Uncategorised

Syntax

Syntax:
params [element1, element2,...elementN]
Parameters:
[element1, element2,...elementN]: Array - format array
elementN: String or Array
String is the name of a private variable (must begin with underscore _, e.g. "_myVar")
Array could be one of the following constructs:
  • [variableName, defaultValue]
  • [variableName, defaultValue, expectedType]
  • [variableName, defaultValue, "ARRAY", expectedArrayLength]
variableName: String - name of a private variable (must begin with underscore _, e.g. "_myVar")
defaultValue: Anything - default value to assign to private variable if passed value is nil
expectedType: String - check if passed value is of a certain type, otherwise fail and return false
expectedArrayLength: Number - if passed value is of type "ARRAY", check that it is of a certain length, otherwise fail and return false
Return Value:
Boolean - true on success, false on failure

Alternative Syntax

Syntax:
argument params [element1, element2,...elementN]
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
[element1, element2,...elementN]: Array - format array
elementN: String or Array:
String is the name of a private variable (must begin with underscore _, e.g. "_myVar")
Array could be one of the following constructs:
  • [variableName, defaultValue]
  • [variableName, defaultValue, expectedType]
  • [variableName, defaultValue, "ARRAY", expectedArrayLength]
variableName: String - name of a private variable (must begin with underscore _, e.g. "_myVar")
defaultValue: Anything - default value to assign to private variable if passed value is nil
expectedType: String - check if passed value is of a certain type, otherwise fail and return false
expectedArrayLength: Number - if passed value is of type "ARRAY", check that it is of a certain length, otherwise fail and return false
Return Value:
Boolean - true on success, false on failure

Examples

Example 1:
[1, 2, 3] call { private ["_one", "_two", "_three"]; _one = _this select 0; _two = _this select 1; _three = _this select 2; // ..... }; // Same as above, only using params [1, 2, 3] call { params ["_one", "_two", "_three"]; // ..... };
Example 2:
[123] call { params ["_myvar"]; }; // Below would produce the same result as above 123 call { params ["_myvar"]; };
Example 3:
position player params ["", "", "_z"]; if (_z > 10) then { hint "YOU ARE FLYING!"; };
Example 4:
[1, nil, 2] params ["_var1", "_var2", "_var3"]; // All 3 variables are made private but only _var1 and _var3 are defined [1, nil, 2] params ["_var1", ["_var2", 23], "_var3"]; // All 3 variables are private and defined
Example 5:
[1, 2] call { if (!params ["_var1", "_var2", ["_var3", true, typeName true]]) exitWith {}; hint str [_var1, _var2, _var3]; }; // The hint shows [1,2,true] [1, 2, 3] call { if (!params ["_var1", "_var2", ["_var3", true, "BOOL"]]) exitWith {}; hint str [_var1, _var2, _var3]; }; // Error! Type Number, expected BOOL
Example 6:
[1, "ok", [1, 2, 3]] call { if (!params [ ["_var1", 0, "SCALAR"], ["_var2", "", typeName ""], ["_var3", [0,0,0], "ARRAY", 3] ]) exitWith {}; hint "ok"; }; // Passes validation [1, 2, [3, 4, 5]] call { if (!params ["_var1", "_var2", ["_var3", [], typeName [], 0]]) exitWith {}; hint "ok"; }; // Fails, because passed array is expected to be of 0 length, i.e. empty
Example 7:
position player params ["_x", "_y"]; player setPos [_x, _y, 100];
Example 8:
[1, 2, 3, [4, 5, 6]] call { params ["_one", "_two", "_three"]; _this select 3 params ["_four", "_five", "_six"]; };
Example 9:
{ _x params ["_group", "_index"]; // ..... } forEach waypoints group player;
Example 10:
fn_someFnc = { params ["_position", ["_direction", 0], ["_name", ""]]; // Extract the x, y, and z from "_position" array: _position params ["_x", "_y", "_z"]; // ..... }; [position player, direction player, name player] call fn_someFnc;

Additional Information

See also:
selectBIS_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

[[Category:Introduced with arma3dev version 1.45]][[ Category: arma3dev: New Scripting Commands | PARAMS]][[ Category: arma3dev: Scripting Commands | PARAMS]]