M1ke_SK 230 Posted July 25, 2016 Hi all, I am trying to get random "_dog" from "all dogs", that have variable "dog == true". Here is what I made. Is it performance friendly? If not, how can I improve it / refactor it? Write your suggestions. init.sqf [] spawn { while {true} do { _dogs = []; { _isDog = _x getVariable ["dog", false]; if(_isDog) then { _dogs = _dogs + [_x]; }; } forEach allUnits - allPlayers; _dog = _dogs call BIS_fnc_selectRandom; sleep 10; }; }; Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted July 25, 2016 Best way would be to add them to a global array, instead of setting a variable and iterating through allUnits in a loop. In the script where you setVariable ["dog",true] replace this with "MyDogsArray pushback _dog". That said, exchange BIS_fnc_selectRandom with the new engine command selectRandom _dogs. Cheers Share this post Link to post Share on other sites
donelsarjo 60 Posted July 25, 2016 _dog = selectRandom ((allUnits - allPlayers) select {getVariable ["dog", false]});Should work, try it. Share this post Link to post Share on other sites