mind 60 Posted September 16, 2015 Dear community, Just a small topic to pin point small but pesky error, hopefully this will help someone find similar problem faster. consider following code myFnc = { //Here we wait for array, but it is optional. //If nothing provided script will manage to do it`s job _array = [_this, 0, [], [[]]] call BIS_fnc_param; _result = 1 + 1; _result; }; call { _input1 = _this select 0; //This is string _input2 = _this select 1; //This is also string ... //Here we run myFnc to get some results //No arguments are provided because they are optional _result = call myFnc; ... } In this case we will get notification message sent from BIS_fnc_param, saying following #0 "text" is type STRING, must be ARRAY. [] used instead. "text" is what was in _input1. Why these problems occur? _this variable contain arguments passed from outer scope. If nothing passed, it does not overwrites, thus still have previous variables as in outer scope. _input1 and _input2 in our case. Finally, param function receive _this variable not empty as you was expected, but with two strings in there, and fires warning message. How to solve? This problem solves simply by providing some arguments to myFnc. Like this _result = [] call myFnc; Have a nice day Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 16, 2015 First of all: Since ArmA 3 1.48, there are the param and params commands which handle what BIS_fnc_param did until than, only that params is faster and a bit better. You should use BIS_fnc_param only where param(s) can't be used, like in forEach loops. The problem is this line: _array = [_this, 0, [], [[]]] call BIS_fnc_param; To be precies, the 4th parameter for BIS_fnc_param: _array = [_this, 0, [], [[]]] call BIS_fnc_param; The 4th parameter (is optional and) is an array which defines the allowed data types (typeName) for the respective parameter. In your case, you defined that only arrays are allowed: [[]] If you want to allow numbers only, use [0] (or any other number). If you want to allow e.g. text AND numbers, it should be ["", 0]. Same with other data types like boolean (true/false), object (objNull) etc. If you omit it, all data types are allow. Share this post Link to post Share on other sites
mind 60 Posted September 16, 2015 The problem is this line: _array = [_this, 0, [], [[]]] call BIS_fnc_param; Thank you. You are absolutely correct. However, the whole question is not about param function, but about how _this variable behave. Param function illustrates this behavior very well. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 16, 2015 "_this" is a "magic variable" which exists in every script and represents the parameter it's called with. someFunction = {hintSilent str _this;}; 123 call someFunction; //hints "123" If you invoke a script by "123 call someFunction" then "_this" is 123 inside that function. If you invoke it with an array, then "_this" is the array and so on. Share this post Link to post Share on other sites
Larrow 2817 Posted September 16, 2015 I think he knows this Johnny, The point he is trying to get across is that if you call a function without sending it parameters the previous scopes _this variable is passed onto the called function. e.g "hello" call { call { call { call { hint str _this; }; }; }; };As all call does is add a scope to the current one, the same reason that local variable are available and can be altered in a call function and is why you need to private your local variables to make sure nothing previously defined can be changed (if desired). "hello" call { _var1 = "_var1 defined in scope 1"; _var2 = "_var2 defined in scope 1"; call { call { systemChat format[ "child scope _this = %1", _this ]; [] call { private[ "_var2" ]; systemChat format[ "final scope _this = %1", _this ]; _var1 = "_var1 changed in called scope"; _var2 = "_var2 changed in called scope"; }; }; }; systemChat format[ "1st scope _this = %1", _this ]; systemChat _var1; systemChat _var2; }; //systemchat output //child scope _this = hello //final scope _this = [] //1st scope _this = hello //_var1 changed in called scope //_var2 defined in scope 1 1 Share this post Link to post Share on other sites