Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » What script(s) in Scratch source code are devoted to saving sb3 files?
- s_federici
-
Scratcher
500+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
I don't know how Scratch source code is organized. So I would be glad if someone could tell me which script(s) in which repository is/are devoted to creating sb3 file to save Scratch projects.
Thanks in advance
Thanks in advance
- mybearworld
-
Scratcher
1000+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
It's in scratch-vm, specifically the saveProjectSb3 function.
- s_federici
-
Scratcher
500+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
Thanks @mybearworld, I found what I needed (scratch code SB3 serialization) in the https://github.com/scratchfoundation/scratch-vm/blob/c4a367f5d4bebf4ac0b300c7a81f6cd8813a1b34/src/serialization/sb3.js file
- Jonathan50
-
Scratcher
1000+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
Does the wiki article help?
- s_federici
-
Scratcher
500+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
Does the wiki article help?
Yes, I used this article (and discovered the weird “shadow blocks”) to further modify my custom Scratch, so that now it still offers the old FOREVER IF block but allow users, if they want, to save the peoject in the standard Scratch format, by replacing the FOREVER IF block with an IF block inside a FOREVER block.
- Jonathan50
-
Scratcher
1000+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
Ah, cool. I remember you from the Snap! topics.Does the wiki article help?
Yes, I used this article (and discovered the weird “shadow blocks”) to further modify my custom Scratch, so that now it still offers the old FOREVER IF block but allow users, if they want, to save the peoject in the standard Scratch format, by replacing the FOREVER IF block with an IF block inside a FOREVER block.
I think the oddest thing is how it's flattened instead of hierarchical (IIRC the internal representation is also something like that).- davidtheplatform
-
Scratcher
500+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
The save format is essentially a flattened AST. It has a lot of weird quirksAh, cool. I remember you from the Snap! topics.Does the wiki article help?
Yes, I used this article (and discovered the weird “shadow blocks”) to further modify my custom Scratch, so that now it still offers the old FOREVER IF block but allow users, if they want, to save the peoject in the standard Scratch format, by replacing the FOREVER IF block with an IF block inside a FOREVER block.I think the oddest thing is how it's flattened instead of hierarchical (IIRC the internal representation is also something like that).
- s_federici
-
Scratcher
500+ posts
What script(s) in Scratch source code are devoted to saving sb3 files?
The save format is essentially a flattened AST. It has a lot of weird quirks
I managed to design a strategy to convert all custom FOREVER IF blocks as IF blocks inside FOREVER blocks. Almost all can be done in just one pass. But I need a second pass to find those blocks (the conditions) that have parents whose ids are in the list of the FOREVER IF blocks' ids (that I collect during the first pass) so to change their parent ids with the ones of the new IF blocks.
I did all the steps manually, and it worked well. Now I have to move to the implementation in Javascript (that I don't know really well, just the basic stuff; I hope my usual “look and replicate” strategy is going to work even this time)
If there are proficient Javascript coders (that are not afraid of looking inside Scratch's source code) let me know, so I know who to contact when I will be soon in trouble

- Discussion Forums
- » Advanced Topics
-
» What script(s) in Scratch source code are devoted to saving sb3 files?