Jump to content

Recommended Posts

Hi, I'm new to scripting so forgive me for what I'm asking.

 

I'm trying to make a training mission for my clan. I need to randomly place four flags inside a given area defined by a marker, and these four flags have some constraints in terms of the position in which they can be placed.

Here's a bit of the code:

traguardo setPos ([["white"], []] call BIS_fnc_randomPos);

blueflag setPos ([[[getPos traguardo, 4500]], [[getPos traguardo, 2500], "water"], _this inArea "white"] call BIS_fnc_randomPos);

where "white" is the name of the above-stated marker.

 

When I run the code, it returns me the error:

|#|_this inArea "white"

Error undefined variable in the expression: _this

don't know why though.

 

Thank you greatly for your help.

Share this post


Link to post
Share on other sites

 

The syntax on the second line is wrong.. try something like:

 

blueflag setPos ( [ [[getPos traguardo, 2500]] , ["water"] ] call BIS_fnc_randomPos );

 

just a guess though....

 

Share this post


Link to post
Share on other sites
4 hours ago, gc8 said:

 

The syntax on the second line is wrong.. try something like:

 


blueflag setPos ( [ [[getPos traguardo, 2500]] , ["water"] ] call BIS_fnc_randomPos );

 

just a guess though....

 

 

Thank you for the answer, still doesn't work though.

Share this post


Link to post
Share on other sites
8 hours ago, italiandrache said:

 


blueflag setPos ([[[getPos traguardo, 4500]], [[getPos traguardo, 2500], "water"], _this inArea "white"] call BIS_fnc_randomPos);

 

 

So, looking at https://community.bistudio.com/wiki/BIS_fnc_randomPos, the third part of the array needs to be CODE, and by that it means it can't just be hanging out there on it's on. So, try wrapping your code in { }:

blueflag setPos ([[[getPos traguardo, 4500]], [[getPos traguardo, 2500], "water"], {_this inArea "white"}] call BIS_fnc_randomPos);

 

  • Like 3

Share this post


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

 

So, looking at https://community.bistudio.com/wiki/BIS_fnc_randomPos, the third part of the array needs to be CODE, and by that it means it can't just be hanging out there on it's on. So, try wrapping your code in { }:


blueflag setPos ([[[getPos traguardo, 4500]], [[getPos traguardo, 2500], "water"], {_this inArea "white"}] call BIS_fnc_randomPos);

 

 

That's it, works a treat. Though it does occasionally return the default world position, which runs counter to the inArea condition. 

@italiandrache What are you trying to do with the blacklist? If I set it to simply ["water"] then everything works great.

blueflag setPos ([[[getPos traguardo, 4500]], ["water"], {_this inArea "white"}] call BIS_fnc_randomPos);

I'm running this in the debug console to watch as positions are found:

null = [] spawn { 
    while {true} do { 
        traguardo setPos ([["white"], []] call BIS_fnc_randomPos); 
        sleep 0.1; 
    }; 
 }; 
  
null = [] spawn {
    while {true} do {
        _pos = [[[getPos traguardo, 4500]], ["water"], {_this inArea "white"}] call BIS_fnc_randomPos;
        blueflag setpos _pos;
        sleep 0.1;
    };
};

After watching for a minute or so I have seen no hits outside the "white" marker area.

Keep in mind that "traguardo" can still be placed in water, as well as outside the marker area if the marker is a hexagon. You can avoid both by doing the same water blacklist and inArea check for it.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you for your help, now it works properly.

With the blacklist array, I'm excluding water from the positions the flag can be placed at, as well as a circular area around the "traguardo" flag previously placed, so that the two flags are at least at a certain distance from each other.

Share this post


Link to post
Share on other sites
2 hours ago, beno_83au said:

 

So, looking at https://community.bistudio.com/wiki/BIS_fnc_randomPos, the third part of the array needs to be CODE, and by that it means it can't just be hanging out there on it's on. So, try wrapping your code in { }:


blueflag setPos ([[[getPos traguardo, 4500]], [[getPos traguardo, 2500], "water"], {_this inArea "white"}] call BIS_fnc_randomPos);

 

 

2 hours ago, Harzach said:

 

That's it, works a treat. Though it does occasionally return the default world position, which runs counter to the inArea condition. 

@italiandrache What are you trying to do with the blacklist? If I set it to simply ["water"] then everything works great.


blueflag setPos ([[[getPos traguardo, 4500]], ["water"], {_this inArea "white"}] call BIS_fnc_randomPos);

I'm running this in the debug console to watch as positions are found:


null = [] spawn { 
    while {true} do { 
        traguardo setPos ([["white"], []] call BIS_fnc_randomPos); 
        sleep 0.1; 
    }; 
 }; 
  
null = [] spawn {
    while {true} do {
        _pos = [[[getPos traguardo, 4500]], ["water"], {_this inArea "white"}] call BIS_fnc_randomPos;
        blueflag setpos _pos;
        sleep 0.1;
    };
};

After watching for a minute or so I have seen no hits outside the "white" marker area.

Keep in mind that "traguardo" can still be placed in water, as well as outside the marker area if the marker is a hexagon. You can avoid both by doing the same water blacklist and inArea check for it.

 

Thank you for your help, now it works properly.

With the blacklist array, I'm excluding water from the positions the flag can be placed at, as well as a circular area around the "traguardo" flag previously placed, so that the two flags are at least at a certain distance from each other.

  • Like 1

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

×