Discuss Scratch

sausagescratch
Scratcher
78 posts

How to get Scratch to JavaScript? Support us now!

-

Last edited by sausagescratch (Jan. 17, 2021 12:32:59)

ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

sausagescratch wrote:

you could then change any parts you want and you'd be free to use it outside of Scratch!
You would probably have to credit Scratch, but nice Idea!

I will try to create something to convert Scratch JSON -> Pseudocode.
ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

ilovericebubbles wrote:

sausagescratch wrote:

you could then change any parts you want and you'd be free to use it outside of Scratch!
You would probably have to credit Scratch, but nice Idea!

I will try to create something to convert Scratch JSON -> Pseudocode.
I'm coming across a problem. I have the variable ‘json’ as the contents of the project.JSON file inside an sb3.
But when I reference a block in the first sprite (the 0th sprite is stage), it comes up with an error.
Here is the reference:
obj.targets[1].blocks.4$mzqKS$7Y`Nr}jjP1f;

the problem is that Scratch identifies blocks as random strings. This contains many reserved characters such as ` , ; and } .

I (for some reason) cannot do \` and \; and \} because it complains about invalid escaping, I cannot do \x64 and such, and I cannot reference it in a string. Good luck figuring it out!


P.S. Yes this is JavaScript in case you forget!
P.P.S Yes I call it ‘JavaScript’ and not ‘Javascript’ or ‘javascript’ or ‘JS’ or ‘js’
P.P.P.S Do you have a problem with that?
P.P.P.P.S Why am I doing this?

Last edited by ilovericebubbles (Nov. 18, 2019 06:47:05)

ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

Bump.
Sheep_maker
Scratcher
1000+ posts

How to get Scratch to JavaScript? Support us now!

ilovericebubbles wrote:

But when I reference a block in the first sprite (the 0th sprite is stage), it comes up with an error.
Here is the reference:
obj.targets[1].blocks.4$mzqKS$7Y`Nr}jjP1f;

the problem is that Scratch identifies blocks as random strings. This contains many reserved characters such as ` , ; and } .
You can do
obj.targets[1].blocks['4$mzqKS$7Y`Nr}jjP1f'];
ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

Sheep_maker wrote:

ilovericebubbles wrote:

But when I reference a block in the first sprite (the 0th sprite is stage), it comes up with an error.
Here is the reference:
obj.targets[1].blocks.4$mzqKS$7Y`Nr}jjP1f;

the problem is that Scratch identifies blocks as random strings. This contains many reserved characters such as ` , ; and } .
You can do
obj.targets[1].blocks['4$mzqKS$7Y`Nr}jjP1f'];
Thanks!
Centuriasoft
Scratcher
46 posts

How to get Scratch to JavaScript? Support us now!

The nice thing about trying to convert Scratch projects to javascript files is that Scratch projects are stored as JSON files, aka JavaScript Object Notation, the hard part is that scratch's JSON files are a convoluted mess

Also, I'm making my own programming language so there are a few things I've learnt, one is this: You can't just ‘translate’ from one language (Scratch) to another (JS) without considerable effort. You have to break down the scratch program into tokens, create an AST, and then reverse that AST into JS code
ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

Centuriasoft wrote:

The nice thing about trying to convert Scratch projects to javascript files is that Scratch projects are stored as JSON files, aka JavaScript Object Notation, the hard part is that scratch's JSON files are a convoluted mess

Also, I'm making my own programming language so there are a few things I've learnt, one is this: You can't just ‘translate’ from one language (Scratch) to another (JS) without considerable effort. You have to break down the scratch program into tokens, create an AST, and then reverse that AST into JS code
You could just parse the JSON into Javascript.
If we could use a Lexicon or YACC in JS, it would probably be reasonably easy.
Lukesstitch
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

This isn't the place for your topic. Instead, go to the Suggestions Forum
-CodePro-
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

-CodePro- wrote:

PullJosh is making one: https://scratch.mit.edu/projects/345789566/
So this was pointless.
NowDeadly
Scratcher
1 post

How to get Scratch to JavaScript? Support us now!

Lukesstitch does it really matter?
sausagescratch
Scratcher
78 posts

How to get Scratch to JavaScript? Support us now!

Nah guys its not pointless because it needs to support cloud variables as well.
sqlmap
Scratcher
23 posts

How to get Scratch to JavaScript? Support us now!

This can be done easily. In fact, I have started making one myself.

All Scratch projects are compiled in JSON. How do you access this JSON? Well, it's very simple. Go to the “See Inside” section of the Scratch project, press File, and hit Download. This will download a sb3 file to your computer - now this file is actually just a zip folder. Change the file extension to zip, and extract it - you should see a json file somewhere among other project assets. Now open that json file in a text editor/viewer, and you will see the project's code in json format! All you need, is a little bit of JavaScript that converts that JSON into working JavaScript code. How? Well, I have recently been using a JavaScript library called “Blocklike” - and you have probably guessed, it's basically Scratch but in JavaScript. You could convert the JSON into Blocklike JavaScript, and you would essentially have a working project outside Scratch. In theory, you could convert it back into a Scratch project, but that could be a little bit harder - and may require Node.js (which is an environment that executes JavaScript code outside of a web browser).

While this is theoretically possible, it would take a considerable amount of time. Supporting cloud variables? Well, you would need a database for that, such as MySQL. I said that I started making a converter myself, well… I had the idea of reading a Scratch sb3 file, and displaying it's block code within a website. A similar idea, however I never got round to making it as i'm busy with other stuff atm.
BlueWonderCam
Scratcher
5 posts

How to get Scratch to JavaScript? Support us now!

Actually, there is already a website that converts scratch to JavaScript. It is here: https://forkphorus.github.io/
trieuminh
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

BlueWonderCam wrote:

Actually, there is already a website that converts scratch to JavaScript. It is here: https://forkphorus.github.io/
That doesn't really do that…
Sheep_maker
Scratcher
1000+ posts

How to get Scratch to JavaScript? Support us now!

trieuminh wrote:

BlueWonderCam wrote:

Actually, there is already a website that converts scratch to JavaScript. It is here: https://forkphorus.github.io/
That doesn't really do that…
It does, but it doesn't show the converted code because it's not made for manual editing, unlike Leopard.
trieuminh
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

Sheep_maker wrote:

trieuminh wrote:

BlueWonderCam wrote:

Actually, there is already a website that converts scratch to JavaScript. It is here: https://forkphorus.github.io/
That doesn't really do that…
It does, but it doesn't show the converted code because it's not made for manual editing, unlike Leopard.
I know it does. That's why I said that it doesn't really do that.
block200
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

NowDeadly wrote:

Lukesstitch does it really matter?
It might not to you but others might find it interesting.
ilovericebubbles
Scratcher
100+ posts

How to get Scratch to JavaScript? Support us now!

Sheep_maker wrote:

trieuminh wrote:

BlueWonderCam wrote:

Actually, there is already a website that converts scratch to JavaScript. It is here: https://forkphorus.github.io/
That doesn't really do that…
It does, but it doesn't show the converted code because it's not made for manual editing, unlike Leopard.
I've had a look at Leopard, I'm not sure if that is what this question was about because it imports a library and then is written like a text-based Scratch.
I think that if you are going to translate Scratch to JavaScript, you want it without any libraries or behind-the-scenes, or ‘vanilla’ if you will.
If you want it like Leopard does, you may as well just have a typed version of Scratch.

Powered by DjangoBB