Jump to content
Sign in to follow this  
Desrat

nested arrays

Recommended Posts

ok I have a nested array in this sort of format (forget the contents this is an example)

array = [[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]];

I then use the following to grab one of the arrays at random

target = array call BIS_fnc_selectRandom;

I would then like to delete the selected item from the original array, so how do I find out what index number has been selected by the BIS_fnc_selectRandom function so that I can delete it (oh and I'm aware it needs making a non array variable first as per the biki instruction) just need to know the index number.

Share this post


Link to post
Share on other sites

I don't understand. Why don't you just delete what BIS_fnc_selectRandom returns? If you want a random index number, you can just use:

floor(random(count array))

Share this post


Link to post
Share on other sites

Why not just pick the index yourself, grab the data and remove the entry. Sometimes it just simpler to make your own.

/* ARRAY call TakeRandom */
TakeRandom = {
   private ["_c", "_idx", "_data"];
   _c = count _this;
   _idx = floor random _c;
   _data = _this select _idx;
   //move swap with very last item
   _this set [_idx, (_this select (_c - 1))];
   //shrink array
   _this resize (_c - 1);
   //return data
   _data
};

Share this post


Link to post
Share on other sites
I don't understand. Why don't you just delete what BIS_fnc_selectRandom returns? If you want a random index number, you can just use:

floor(random(count array))

thats a fair point :)

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  

×