I'm trying to distribute 10 x and y coordinates to 20 variables. I'm using random and splice so that i don't have to scramble the values inside the array. Then i need not worry since the last element is removed.
The array is for a 5 x 2. When i use splice, I end up with the same coordinate for example (248,445) x2.. so these 2 pictures i show overlaps instead, which is wrong.
The array is for a 5 x 2. When i use splice, I end up with the same coordinate for example (248,445) x2.. so these 2 pictures i show overlaps instead, which is wrong.
JavaScript:
var xpos = [248, 316, 384, 452, 520, 248, 316, 384, 452, 520];
var ypos = [445, 445, 445, 445, 445, 503, 503, 503, 503, 503];
$gameVariables.setValue(22, xpos);
$gameVariables.setValue(23, ypos);
var arr = $gameVariables.value(22);
$gameVariables.setValue(41, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(42, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(43, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(44, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(45, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(46, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(47, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(48, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(49, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(50, arr.splice(Math.floor(Math.random() * arr.length), 1));
var arr2 = $gameVariables.value(23);
$gameVariables.setValue(51, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(52, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(53, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(54, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(55, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(56, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(57, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(58, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(59, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(60, arr2.splice(Math.floor(Math.random() * arr2.length), 1));