scratchfoundation / scratch-gui

Graphical User Interface for creating and running Scratch 3.0 projects.
https://scratchfoundation.github.io/scratch-gui/develop/
BSD 3-Clause "New" or "Revised" License
4.42k stars 3.5k forks source link

(x position) in script should be rounded like XX.XX #1372

Closed apple502j closed 6 years ago

apple502j commented 6 years ago

Expected Behavior

Scratch 2.0: 2.0 is rounded

Actual Behavior

Scratch 3.0: 3.0 isn't rounded

Steps to Reproduce

Program like:(see also image)

when green flag clicked
go to x:(pick random -240**.0** to 240**.0**) y:(pick random -180**.0** to 180**.0**)

Operating System and Browser

firefox 58.0.1 windows7 HomePremium 64bit sp1

(y position) should, too.

LukeSchlangen commented 6 years ago

I'd like to help with this! Would the random number be rounded, or the value in the say block? (Should we round the value from the random number generator or just round any number before it enters the say block?)

towerofnix commented 6 years ago

@LukeSchlangen Assuming the objective here is to be compatible with Scratch, the say block should round whatever values are passed to it. You can test this in Scratch 2.0 - the say block will say 1.23 when you pass the number 1.234. Do note you have to pass the number 1.234, not the string, and that it will display the number in full precision if it's a string. Here's a simple test script:

Test script

say [1.234] for 1 secs  //............... Input is a string: "1.234"
say (0 + 1.234) for 1 secs  //........... Input is a number: "1.23"
say (join [] (0 + 1.234)) for 1 secs  //. Input is a string: "1.234"
LukeSchlangen commented 6 years ago

Great! So I'm guessing this will be a type check for number and then rounding? I'm digging through the code base for the first time and it seems like this logic might not be a part of scratch-gui but a part of scratch-blocks? Do you have any advice on where I might look to get started?

towerofnix commented 6 years ago

Yup, a type check and then rounding should do it.

The code for this would actually probably be in scratch-vm -- the VM repository contains all the code which makes blocks actually do things. (scratch-blocks is for the rendering of blocks and the block workspace, and contains all the Blockly-related code, but none of the actual runtime behavior, which is in scratch-vm. scratch-gui is the code which puts together the VM and scratch-blocks (as well as a few other components, like scratch-render) to make the complete Scratch 3.0 editor.)

Generally, when you want to look for the implementation of a block, you should check in the /src/blocks directory of scratch-vm; in this case, we want to look at src/blocks/scratch3_looks.js. That file contains a class Scratch3LooksBlocks which has a function say, which is the one you'll want to modify. (I knew that we need to change say because the function getPrimitives, which every Scratch3(Category)Blocks class has, pointed "looks_say" to the say function.)

LukeSchlangen commented 6 years ago

Thank you! It sounds like you probably could have resolved this issue by now, but I appreciate you letting me take a crack at it!

towerofnix commented 6 years ago

It's good to have new contributors, and I enjoy helping out with this - plus now you know how to work on the Scratch 3.0 VM in general :)

LukeSchlangen commented 6 years ago

I believe this PR should resolve this issue (took me a while to properly write the unit test). https://github.com/LLK/scratch-vm/pull/925

Clark-E commented 6 years ago

@apple502j this looks to be resolved. You should close this issue. 👍