Jump to content
Sign in to follow this  
Socrate

Pass by Reference in SQF

Recommended Posts

Is it possible to pass params to an sqf function by reference?

Like arrays for examples? or are they already passed by reference?

Thanks

Socrate

Share this post


Link to post
Share on other sites

Arrays are always passed by reference and if you want to pass something else by reference, put it in an array first, and then you pass that array:

A_FUNCTION_THAT_MODIFIES_THE_GIVEN_ARRAY = {
  _this set [0, objNull];
  _this set [1, false];
  _this set [2, -78];
};

_params = [
  player,
  true,
  12
];
_params call A_FUNCTION_THAT_MODIFIES_THE_GIVEN_ARRAY;

hint format["%1", _params];

And if your intention would be to leave to original array untouched, you'd have to make a copy prior to modifying it:

A_FUNCTION_THAT_MODIFIES_THE_GIVEN_ARRAY = {
  _copy = +_this;
  _copy set [0, objNull];
  _copy set [1, false];
  _copy set [2, -78];

  _copy
};

Edited by ruebe

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  

×