Add one to index if random costume is current costume

This commit is contained in:
Kenny2github 2018-05-09 08:13:04 +08:00
parent 3f1c4aa2d8
commit 8e9f9e0a30

View file

@ -346,11 +346,9 @@ class Scratch3LooksBlocks {
} else if (requestedCostume === 'random backdrop') { } else if (requestedCostume === 'random backdrop') {
const numCostumes = target.getCostumes().length; const numCostumes = target.getCostumes().length;
if (numCostumes > 1) { if (numCostumes > 1) {
let index; let selectedIndex = Math.floor(Math.random() * (numCostumes - 1));
do { if (selectedIndex === target.currentCostume) selectedIndex += 1;
index = Math.floor(Math.random() * numCostumes); target.setCostume(selectedIndex);
} while (index === target.currentCostume);
target.setCostume(index);
} }
} else { } else {
const forcedNumber = Number(requestedCostume); const forcedNumber = Number(requestedCostume);