From 8e9f9e0a30d5da540e750f1aa33b647aa8e903fa Mon Sep 17 00:00:00 2001 From: Kenny2github Date: Wed, 9 May 2018 08:13:04 +0800 Subject: [PATCH] Add one to index if random costume is current costume --- src/blocks/scratch3_looks.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index a2c9dbefb..310d9a3de 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -346,11 +346,9 @@ class Scratch3LooksBlocks { } else if (requestedCostume === 'random backdrop') { const numCostumes = target.getCostumes().length; if (numCostumes > 1) { - let index; - do { - index = Math.floor(Math.random() * numCostumes); - } while (index === target.currentCostume); - target.setCostume(index); + let selectedIndex = Math.floor(Math.random() * (numCostumes - 1)); + if (selectedIndex === target.currentCostume) selectedIndex += 1; + target.setCostume(selectedIndex); } } else { const forcedNumber = Number(requestedCostume);