Merge pull request #1122 from Kenny2github/develop

Handle random backdrop menu option
This commit is contained in:
kchadha 2018-05-09 10:12:05 -04:00 committed by GitHub
commit cf8ad388de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -343,6 +343,13 @@ class Scratch3LooksBlocks {
} else if (requestedCostume === 'next costume' ||
requestedCostume === 'next backdrop') {
target.setCostume(target.currentCostume + 1);
} else if (requestedCostume === 'random backdrop') {
const numCostumes = target.getCostumes().length;
if (numCostumes > 1) {
let selectedIndex = Math.floor(Math.random() * (numCostumes - 1));
if (selectedIndex === target.currentCostume) selectedIndex += 1;
target.setCostume(selectedIndex);
}
} else {
const forcedNumber = Number(requestedCostume);
if (!isNaN(forcedNumber)) {