scratchfoundation / scratch-vm

Virtual Machine used to represent, run, and maintain the state of programs for Scratch 3.0
http://scratchfoundation.github.io/scratch-vm/
BSD 3-Clause "New" or "Revised" License
1.2k stars 1.49k forks source link

Repeat blocks handle decimals differently in 3.0 #1473

Closed BryceLTaylor closed 6 years ago

BryceLTaylor commented 6 years ago

It appears that if you put a decimal in a repeat block (Repeat 3.5 times) in 2.0 it seems to round to the nearest integer while 3.0 seems to use floor and always round down. You can see that in this project: https://llk.github.io/scratch-gui/develop/compatibility-testing.html#238650956 In which I change several variables by 1 in repeat loops that all have decimals in them.

screen shot 2018-08-14 at 5 19 01 pm

And also in this project: https://llk.github.io/scratch-gui/develop/compatibility-testing.html#188149848 which uses a repeat to change the ghost effect on the Thumbnail sprite 2.5 times. In 2.0 this changes it 3 times while in 3.0 it changes it 2 times.

towerofnix commented 6 years ago

Fix is changing Math.floor to Math.round here: https://github.com/LLK/scratch-vm/blob/f9814a5f884df836da4da8f249a27e5ea9861460/src/blocks/scratch3_control.js#L52

I can make a PR if (this is labelled help-) wanted :P

Edit: Oops I accidentally made the PR (with a unit test) anyways. Sorry. #1475

mrjacobbloom commented 6 years ago

This could relate to the discussion in #202, though in this case compatibility is probably more important than consistency

Mr-Dave2 commented 6 years ago

Dup of Repeat block treats its argument differently than in Scratch 2.0 #1083

thisandagain commented 6 years ago

Tracking in https://github.com/LLK/scratch-vm/issues/1083. @towerofnix I added "help wanted" to that issue. :-)

towerofnix commented 6 years ago

@thisandagain Ah right, updated the PR so it auto-closes that issue once it's merged!