italiandrache 11 Posted March 13, 2020 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
gc8 981 Posted March 13, 2020 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
italiandrache 11 Posted March 13, 2020 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
beno_83au 1369 Posted March 14, 2020 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); 3 Share this post Link to post Share on other sites
Harzach 2518 Posted March 14, 2020 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. 2 Share this post Link to post Share on other sites
italiandrache 11 Posted March 14, 2020 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
italiandrache 11 Posted March 14, 2020 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. 1 Share this post Link to post Share on other sites
Harzach 2518 Posted March 14, 2020 Ah, of course. Works nicely. 3 Share this post Link to post Share on other sites