-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropped sprite names that are numbers do not work #1743
Comments
I'm not sure whether the runtime's getSpriteTargetByName function should do a cast to string itself, or if each block implementation should do the cast. We generally do casting like this in the block implementations, but obviously that is error prone already, where we miss cases (e.g. the current bug). cc @cwillisf |
@kchadha Yeah, the "round" block returns a JavaScript Number, whereas the raw variable block returns a JavaScript String. We still need to have the distinction because things like the "switch to costume" blocks take the type of the data into account if there is a costume with a name that is a number. In Scratch 2.0, it can be seen that double equality (i.e. with type coercion) is used at the level of the function which gets a sprite by name: https://github.com/LLK/scratch-flash/blob/develop/src/scratch/ScratchStage.as#L148 I would therefore argue that we should be able to safely do the same in Scratch 3.0 without breaking things @ericrosenbaum |
@ktbee, I think @joker314 meant to tag you in that response. In regards to @ericrosenbaum's question, I looked at all the places where See the tests @joker314 added in #1517 for more details on how those blocks should behave. |
Thank you for taking a look @joker314 @kchadha! I also dug into this a bit and have a better sense of @ericrosenbaum's question now. Initially I was thinking the same thing as @kchadha, that we should just always cast the sprite name to a string if we need to in @kchadha for the time being, do you have a preference between fixing this one block or casting to a string in |
@ktbee, I'm fine with fixing it in the original blocks if there is going to be an optimization for the casting. Maybe file an issue for that so that @mzgoddard's work can reference that and this discussion can be tracked. For fixing it in the original blocks, it would be good to make sure that it's fixed in all of the places that @ericrosenbaum's original description mentions:
|
@ktbee I'm fine with either approach. If you go with the former, it would be good to track the idea of needing to cast in one place in an issue (so that this discussion can be tracked and @mzgoddard can reference the issue when that's been fixed). If you decide to fix it in the individual block definitions, it would need to get fixed for the following blocks mentioned in @ericrosenbaum's PR description (and any others that have a pluggable input that could possibly reference a sprite name):
|
Sounds good @kchadha! And thank you for (re)enumerating the blocks that should have the string casting added, I had missed that in @ericrosenbaum's original description. I'll file the optimization issue for @mzgoddard and add string casting to those blocks. |
Resolved by #2038 |
Expected Behavior
It should be possible to drop a variable that reports a number onto an input that expects a sprite name in order to select a sprite with a name that is a number.
This bug affects any block that accepts a sprite name as an input:
For example, here the bananas are a sprite named "3" and dropping blocks reporting the number 3 onto the "distance to" block works correctly in Scratch 2.0:
I saw this issue while trying out the "chaos game" project, which currently does not work at all in 3.0, because it uses both "point toward" and "distance to" with dropped numeric values to refer to sprites:
https://scratch.mit.edu/projects/243588792/
https://llk.github.io/scratch-gui/develop/#243588792
Actual Behavior
In 3.0, the same blocks report 10,000:
Steps to Reproduce
The text was updated successfully, but these errors were encountered: