Closed spectranaut closed 5 years ago
Hmm -- cool bug! I might be mistaken, but I don't think this affects Scratch 3.0: fixing the bug won't break (nor fix) existing projects; and we can't turn the 0s back into Infinities because what if the user actually put a 0? Do you agree?
@joker314 it might just be something to keep in mind when people are implementing scratch 3 saving! I agree probably not worth fixing in scratch 2 :)
Duplicate of https://github.com/LLK/scratch-flash/issues/1290 (Though I guess it's worth having the compatibility discussion, since I can't see an obvious reason why Scratch 3 should save ±Infinity as zero, unless someone can conjure up some plausible case why Scratch 2 behaved in this way, and why Scratch 3 needs to follow on and be compatible.)
/cc @kchadha @ktbee
For some more context, this actually is a problem for saving scratch3 projects:
In Scratch3, the variable gets serialized using JSON.stringify, which does not work with values like Infinity
or NaN
(see here for why), so they get serialized to null
, which then makes the parser fail. that makes the project not loadable by file input, and cannot be saved on the server because validation fails (null is not a number or string).
Found by @ericrosenbaum
Thanks @paulkaplan and @ericrosenbaum. I'm raising the priority of this to "critical" and pushing it up in the compatibility project backlog.
/cc @ktbee @kchadha
How should we solve this problem? Do we want to do the same thing as scratch 2 and serialize Infinity and NaN as 0?
@kchadha That seems like the right way to resolve the issue IMO.
But then Infinity and NaN get weird when stored... why not use a custom serializer or at least a third-party one that handles such values properly?
Expected Behavior
In scratch 2: You should be able to save the value (1/0) (constructed using the
() / ()
operator block). The value is listed asInfinity
in the list or variable.Actual Behavior
In scratch 2: You cannot save the value (1/0) (constructed using the
() / ()
operator block). The value is listed asInfinity
, then is turned into0
in the sb2 creation.Steps to Reproduce
() / ()
operator block) using theset () to ()
block.() / ()
operator block) to the list using theadd () to ()
block.Infinity
in the visual representation of the list or variable.0
b. If you inspect the project.json, the value there is0
as wellSee this project for an example: https://scratch.mit.edu/projects/260496681/#editor
This may or may not be a compatibility issue with scratch 3.
Operating System and Browser
Debian 10 and Firefox 62