Jump to content
Sign in to follow this  
MaxPower44

Trouble with function

Recommended Posts

I have write a function like this:</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">private {_param1,param2,_count};

_param1 = _this select 0;

_count = 0;

_return = 1;

while (_count < _param1) do {

  _return = _return * _param1;

  _param1 = _param1 - 1;

};

_return<span id='postcolor'>

And i call like this :</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_count=0;

_array = [1,2,45,18]

#loop

  player sidechat format["%1", [_array select _count] call mafunction

?(_count< count _array):goto "Loop"<span id='postcolor'>

But, i mean that my variable _count of the script is modify by the function, or not ?

I should change the _count in script by _count2, what's wrong ?

Share this post


Link to post
Share on other sites
Guest

"_count" is a local variable. It should not be modified by the function.

Share this post


Link to post
Share on other sites

I think, the variables are not properly 'privatized' in your function. The private command should look like:

private ["_param1", "_param2", "_count"];

Share this post


Link to post
Share on other sites

You're probable right, in the example in comref, i saw :</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">    private {"_a","_b"};

   _a = _this select 0;

   _b = _this select 1;

   if (_a>_b) then {_a} else {_b}<span id='postcolor'>

But I make :</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">    private {_a,_b};

   _a = _this select 0;

   _b = _this select 1;

   if (_a>_b) then {_a} else {_b}<span id='postcolor'>

Thx

Share this post


Link to post
Share on other sites

Make sure to use square brackets though, its

private ["_a", "_b"];

and not

private {"_a", "_b"};

Share this post


Link to post
Share on other sites
Guest

private ["_a","_b"] is the standard variant. I havn't tried the other.

It would be however strange that it works since curled brackets are the same as string delimiters.

{hello world} = "hello world"

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  

×