Merge pull request #2101 from knandersen/bugfix/2086

Fix #2086 by resolving pending promise even when power set to 0%
This commit is contained in:
Kevin Nørby Andersen 2019-04-09 15:43:09 -04:00 committed by GitHub
commit eb66855539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -372,9 +372,11 @@ class BoostMotor {
* Scale the motor power to a range between 10 and 100,
* to make sure the motors will run with something built onto them.
*/
const p = MathUtil.scale(value, 0, 100, 10, 100);
this._power = p;
if (value === 0) {
this._power = 0;
} else {
this._power = MathUtil.scale(value, 1, 100, 10, 100);
}
}
/**
@ -475,7 +477,11 @@ class BoostMotor {
* @param {number} direction - rotate in this direction
*/
turnOnForDegrees (degrees, direction) {
if (this.power === 0) return;
if (this.power === 0) {
this.pendingPromiseFunction();
return;
}
degrees = Math.max(0, degrees);
const cmd = this._parent.generateOutputCommand(
@ -1654,8 +1660,8 @@ class Scratch3BoostBlocks {
motor.pendingPromiseFunction = null;
}
return new Promise(resolve => {
motor.turnOnForDegrees(degrees, sign);
motor.pendingPromiseFunction = resolve;
motor.turnOnForDegrees(degrees, sign);
});
}
return null;