Jump to content
Sign in to follow this  
voidbyte

making parameter optional with isNil

Recommended Posts

Hello, 

 

I am kinda stuck actually. I have a function.
And I want to set a default value, if the function is called without paramters.
The reason behind is: There is no need to use a parameter if you dont want to return a specific answer from the function. So I tried to make my life easier with this:
 

private ["_isBossTrue", "_setBoss"];
params ["_adminPlayer"];

if ( isNil {_this select 0}) then {_adminPlayer = 0;}
_adminPlayer = _this select 0;


if (_adminPlayer == 1) then { ...

 

so trying to call the it with:

_whatPlayerIsIt = [0] call fnc_checkPlayer;

works fine.
 

_whatPlayerIsIt = call fnc_checkPlayer;

does not.

 

This function might grow up.. and I dont wanna end up with pen and paper, writing down what params I have to use, even if they are not necessary.
Any ideas?

 

 

Share this post


Link to post
Share on other sites

These two commands do exactly what you want:

param

params
 

So the "param" command would be used as such:

_adminPlayer = param [0,<DEFAULTVALUE>];

 

The reason why your second example doesn't work is because "_this" is nil there, so "_this select 0" results in nonsense.

  • Like 1

Share this post


Link to post
Share on other sites

gosh... you made my day!
Thank you for that!

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
Sign in to follow this  

×