Jump to content
SerbiX8

Difference between params and select commands.

Recommended Posts

Hello,

 

Can somebody explain me what's the difference between params and select commands?

 

For example, we have 2 functions:

fnc_someFunc={
params ["_argument1","_argument2"];
//...//
};

[_argument1,_argument2] call fnc_someFunc;

And

fnc_someFunc={
_argument1 = _this select 0;
_argument2 = _this select 1;
//...//
};

[_argument1,_argument2] call fnc_someFunc;

So what's the difference between these commands?

 

I apologize if this question is dumb but I really can't understand the difference.

 

Thanks.

Share this post


Link to post
Share on other sites

Params is a dedicated command to declare parameters inside a function, automatically making the declared variables private with the possibility of returning default values/types if no parameter was given.

It's more readable than having to use private, _this select 0 and "if then else" statements if no input parameter is given.

 

TAG_fnc_function = {

	params [["_test","Parameter missing"]];
	hintsilent _test;

};

["Hello"] call TAG_fnc_function//prints "Hello"
call TAG_fnc_function//prints "Parameter missing"

//to do the same without params you need to do this:
TAG_fnc_function = {

	private ["_test"];
	_test = if (isNil {_this select 0}) then {"Parameter missing"} else {_this select 0};
	hintsilent _test;

};

Wiki article has some good examples.

 

5 minutes ago, Smitt14ua said:

Params defines variables in private type (only in some namespace)

 

And what namespaces would that be?

 

Cheers

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
1 minute ago, Grumpy Old Man said:

And what namespaces would that be?

It was a simple definition of private variable. 

Share this post


Link to post
Share on other sites
1 minute ago, Smitt14ua said:

It was a simple definition of private variable. 

Namespace has nothing to do with private. Are you mistaking it with scope perhaps?

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, Grumpy Old Man said:

Namespace has nothing to do with private. Are you mistaking it with scope perhaps?

 

Cheers

Ya, excuse me :f: Scope

  • Like 1

Share this post


Link to post
Share on other sites

So the main feature of params command is that I don't have to define each argument in call command for the function to work, right?

Share this post


Link to post
Share on other sites
7 minutes ago, SerbiX8 said:

So the main feature of params command is that I don't have to define each argument in call command for the function to work, right?

Why?

private _name = _this select 0;

private _type = _this select 1;

...

Some:

params ["_name", "_type", ...];

And this works fine with call and other

Share this post


Link to post
Share on other sites

It's easier and cleaner to look use. The params hasn't been around all that long, maybe last 2 years? It's a welcome addition to the command library.

Share this post


Link to post
Share on other sites
9 minutes ago, Smitt14ua said:

Why?

private _name = _this select 0;

private _type = _this select 1;

...

Some:

params ["_name", "_type", ...];

And this works fine with call and other

 

18 minutes ago, SerbiX8 said:

So the main feature of params command is that I don't have to define each argument in call command for the function to work, right?

 

It is my understanding from what Old Man said:

34 minutes ago, Grumpy Old Man said:

TAG_fnc_function = { params [["_test","Parameter missing"]]; hintsilent _test; }; ["Hello"] call TAG_fnc_function//prints "Hello" call TAG_fnc_function//prints "Parameter missing" //to do the same without params you need to do this: TAG_fnc_function = { private ["_test"]; _test = if (isNil {_this select 0}) then {"Parameter missing"} else {_this select 0}; hintsilent _test; };

Share this post


Link to post
Share on other sites

If u about missing arguments, better use params and way of defines that Old Man said

Share this post


Link to post
Share on other sites
2 minutes ago, Smitt14ua said:

If u about missing arguments, better use params and way of defines that Old Man said

 

Yep, that's what I was talking about.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×