TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

fix: wedo2 stop motor when power set to 0 #198

Closed tpsnt closed 7 months ago

tpsnt commented 7 months ago

When wedo2 motor power set to 0, the motor stops.

Resolves

When wedo2 motor power set to 0, the motor won't stop. And motorOff() won't stop the motors either.

Proposed Changes

This change adds a judge statement. When a startMotorPower() is invoked, it checks args.POWER. If args.POWER === 0, call a motor.turnOff first, then change the power attribute of the motor.

Reason for Changes

In WeDo2Motor.turnOff(), if this._power === 0, it returns immediately. In Scratch3WeDo2Blocks.startMotorPower(), if args.POWER === 0, WeDo2Motor.turnOn() returns immediately. So when you call Scratch3WeDo2Blocks.startMotorPower({POWER:0}), you won't turnOff() the motor, until you set the power to a number other and 0.

Test Coverage

Scratch3WeDo2Blocks.startMotorPower({POWER:0}); WeDo2Motor.turnOff();

GarboMuffin commented 7 months ago
tpsnt commented 7 months ago
  • can you make it an if/else so that you're only calling either turnOn or turnOff, not both (yes I know the turnOn will do nothing, but that is still weird code)
  • is Scratch aware of this / is there a PR open up there?

https://github.com/scratchfoundation/scratch-vm/pull/4207 but scratchfoundation doesn't reply to me, and there isn't open issues there.