Jump to content
Tankbuster

private statement, alternative syntaxs?

Recommended Posts

I'm sure I saw someones code that had a private statement that was assigning a value to the variable as well as privating it.

 

The biki has an example where a single variable is created, privated and given a value, but I'm sure this code I saw had the array version where it could be done to numerous ones. I've been guessing the syntax, but get various errors back.  For example

 

private ["_spawnpos" = islandcentre, "_testradius" = 2];

//missing closing square bracket error

 

Does anyone know the correct syntax I'm on about?

Share this post


Link to post
Share on other sites

PS, what's the plural of syntax? :)

Share this post


Link to post
Share on other sites

Syntaxes - like the many taxes you pay to our lovely government.

 

You can do:

private _myVar = 2;
private _anotherVar = "someString";

 

But i didn't think you could do that in an array.

  • Like 1

Share this post


Link to post
Share on other sites

Yeah, that's how I'm doing it now, individual statements for each variable, but I'm sure I saw an array type. If only I could remember whose code it was!

Share this post


Link to post
Share on other sites

maybe you're talking about the params command. 

params [["_o",-1],["_disp",displayNull],["_val",0]];

which is not really what you're looking for

Share this post


Link to post
Share on other sites

What xjoker said
 

[islandcentre, 2] params ["_spawnpos", "_testradius"];

 

  • Like 1

Share this post


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

What xjoker said
 


[islandcentre, 2] params ["_spawnpos", "_testradius"];

 

 

Right, I understand that. Does that work as a private statement in the bottom scope?

Share this post


Link to post
Share on other sites
11 minutes ago, Tankbuster said:

Right, I understand that. Does that work as a private statement in the bottom scope?


From biki page description:
 

Quote

Parses input argument into array of private variables...

 

Not sure what else you need to hear

Share this post


Link to post
Share on other sites

You could do a test if you are not sure:

_zero = nil;
{
    _x params ["_zero"]
} forEach [
    [0],
    [0],
    [0],
    [0]
];
diag_log format ["is zero nil? %1", isNil "_zero"];
diag_log format ["value of _zero%1", _zero];

I suspect it's private to whatever scope it was defined in.  Can't check - watching football

Share this post


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


From biki page description:
 

 

Not sure what else you need to hear

 

Yes, thanks. Perhaps something added to the private might be in order?

Share this post


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

done

Nie one. Thanks.

Share this post


Link to post
Share on other sites

The usual way is to list all of the variables then post defined equal to.

Something like this...


private ["_group","_pos","_max_area","_behav","_allowwater","_min_area"];



_group = _this select 0;

_pos = _this select 1;

_max_area = _this select 2;

if (_max_area < 50) then {_min_area = 0;} else {_min_area = 50;};

_behav = _this select 3;
 
   
   
   
   
   
   

Share this post


Link to post
Share on other sites

That certainly was the usual way. But with the recent extension to private and the introduction of params I will never write so many lines again when I can just do:

 

params ["_group", "_pos", "_max_area", "_behav"];
private _min_area = if (_max_area < 50) then {0} else {50};

 

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, Muzzleflash said:

That certainly was the usual way. But with the recent extension to private and the introduction of params I will never write so many lines again when I can just do:

 


params ["_group", "_pos", "_max_area", "_behav"];
private _min_area = if (_max_area < 50) then {0} else {50};

 

 

Or you could take it one step further:
 

_max_area = random 100;
private _min_area = if (_max_area < 50) then {0} else {50};
//0.0023 ms

_max_area = random 100;
private _min_area = [0,50] select (_max_area < 50);
//0.0019 ms - less to write and ~20% faster -> win/win

Select owns so hard, I love it.

Final one line result:

params ["_group", "_pos", "_max_area", "_behav",["_min_area",[0,50] select (_max_area < 50)]];

 

Cheers

Share this post


Link to post
Share on other sites

private _min_area = [50,0] select (_max_area < 50);

 

 

  • Like 1

Share this post


Link to post
Share on other sites
On 6/11/2017 at 8:03 AM, Grumpy Old Man said:

Final one line result:


params ["_group", "_pos", "_max_area", "_behav",["_min_area",[0,50] select (_max_area < 50)]];

 

Won't work

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, killzone_kid said:

 

Won't work

True that, since _max_area isn't defined at that point.

This and my logical error pointed out by @pierremgi could be solved like this:

params ["_group", "_pos", "_max_area", "_behav"];
private _min_area = [50,0] select (_max_area < 50);

Cheers

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

×