Jump to content
Sign in to follow this  
TheGeneral2899

selectRandom from Array, then remove from original Array

Recommended Posts

Seems to have gotten me stuck after an hour or so of searching. 

1)  Array of 10 unit names

2)  Use Bis_fnc_selectRandom from them to choose one random of them.

3)  *ISSUE* I want to create a new array of the remaining 9 units (minus the one that was random).

 

// Array of all possible locations (items are pens for placement reasons)
_potentialLoc = [bomb1,bomb2,bomb3,bomb4,bomb5,bomb6,bomb7,bomb8,bomb9,bomb10];

// selects randomized location for bomb
_bombRandom = _potentialLoc call BIS_fnc_selectRandom;  

// gets position of randomly selected bomb
_bombLoc = getPosATL _bombRandom;

//Creates the bomb box and then the detonante script
bombActual = createVehicle ["CUP_ammobednaX", _bombLoc, [], 0, "CAN_COLLIDE"];
_disarmBomb = [bombActual] execVM "detonate.sqf";

// Create new array of remaining false bomb locations
// HERE IS MY ISSUE
_fakeBombLoc = _potentialLoc - _bombRandom;
sleep 3;
hint str _fakeBombLoc; // [1,2,3] 

When attempting to print it out, I still get the full list of 10 bomb locations despite.

 

Any help would be greatly appreciated!  Thanks!

Share this post


Link to post
Share on other sites

Figured out the issue.  

 

Previous code:

_fakeBombLoc = _potentialLoc - _bombRandom;

 

Fixed code:

_fakeBombLoc = _potentialLoc - [_bombRandom];

Share this post


Link to post
Share on other sites

_potentialLoc = [bomb1,bomb2,bomb3,bomb4,bomb5,bomb6,bomb7,bomb8,bomb9,bomb10];

_bombRandom = _potentialLoc deleteAt (floor random count _potentialLoc);

 

now _potentialLoc returns the 9 remaining bombs.

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  

×