I have a box with 5 pieces of paper inside
myArray1 = new Array (“1”,“2”, “3”, “4”, “5”);
I am going to chose a piece at random from the box
$i = random(5);
trace(myArray1[$i]);
That piece has now been removed from the box, therefor it has to be removed from the array, now I can’t find any tutorials on how to remove from mid-array only begining and end, so I thought of this,
for (var $loop = 0; $loop < myArray1.length(); $loop++)
{
if ($loop <> $i)
{
myArray2 = new Array();
myArray2.push(myArray1[$loop]);
}
}
trace(myArray2);
Now maybe I am wrong in how I have set this up, but im thjinking if the loop index of the random piece is equal to the random number, then skip that, else, put all the other pieces in a new box.
but when i trace the 2nd array, it displays the random value.
I don’t know what I am doing wrong. Is there any way to move everything from an array into a new array WITHOUT a certain element? I mean I know you can move a certain element via its array possition, any form of array.pushNOT($n, ($n+1))
:hangover: