Closed apple502j closed 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?)
@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:
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"
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?
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.)
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!
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 :)
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
@apple502j this looks to be resolved. You should close this issue. 👍
Expected Behavior
Scratch 2.0:
Actual Behavior
Scratch 3.0:
Steps to Reproduce
Program like:(see also image)
Operating System and Browser
firefox 58.0.1 windows7 HomePremium 64bit sp1
(y position) should, too.