Discuss Scratch
- Discussion Forums
- » Open Source Projects
- » How does Scratch work?
- scratcher2286
-
79 posts
How does Scratch work?
I read the Scratch 3.0 source code, but it is a mess.
If I make a game, how does Scratch interpret it?
If I code a game, how does Scratch render the blocks and stuff?
I am trying to make my own Scratch replica that's why I am asking those questions.
If I make a game, how does Scratch interpret it?
If I code a game, how does Scratch render the blocks and stuff?
I am trying to make my own Scratch replica that's why I am asking those questions.
- PyraEthan12
-
1000+ posts
How does Scratch work?
Scratch blocks are a sort of JavaScript which is used in block form. While the blocks are not “real” programming.
- scratcher2286
-
79 posts
How does Scratch work?
I know that those blocks are just simple JSON data. But how does the interpreter, Scratch VM, runs those blocks? Scratch blocks are a sort of JavaScript which is used in block form. While the blocks are not “real” programming.
- -_Puppy_-_Vibes_-
-
57 posts
How does Scratch work?
You stack the blocks to make an algorithm. It is easier than it looks! Watch this for the basics.
- PyraEthan12
-
1000+ posts
How does Scratch work?
It’s not “magic” it’s programmed to function. it is just magic.
why do you ask?
- scratcher2286
-
79 posts
How does Scratch work?
It is NEVER magic that's why I asked. it is just magic.
why do you ask?
However I don't know what happens behind my project when I run it.
My question explaination:
See these blocks:
when green flag clickedI know what happens: When the green flag is clicked, the cat says Hello indefinitely and waits and says nothing again.
say [Hello]
wait (2) secs
say []
However, I wonder how each block's got to run, do their thing, and display what they had made to the sprite in the stage.
I also wonder how Scratch knows if you pressed the key, clicked the green flag, etc.
But here's a bit tricky to answer: How cloud variables work?
Well I will listen to all your replies to create my Scratch replica.
Thank you
Last edited by scratcher2286 (Nov. 29, 2022 09:32:42)
- RalphJP
-
31 posts
How does Scratch work?
You can read all the code for scratch in an understandable format here: https://github.com/LLK
The code specifically for the blocks is here: https://github.com/LLK/scratch-vm/tree/develop/src/blocks
Basically scratch looks for an event block, then find then looks for a bit of JSON which says “next” followed by the block id. It then calls a JavaScript function to run that block, then it looks for another “next” in the JSON the runs that block and so on.
The green flag (And all the other buttons on scratch) has a JavaScript event listener which waits until the flag is clicked.
The code specifically for the blocks is here: https://github.com/LLK/scratch-vm/tree/develop/src/blocks
Basically scratch looks for an event block, then find then looks for a bit of JSON which says “next” followed by the block id. It then calls a JavaScript function to run that block, then it looks for another “next” in the JSON the runs that block and so on.
The green flag (And all the other buttons on scratch) has a JavaScript event listener which waits until the flag is clicked.
- CST1229
-
1000+ posts
How does Scratch work?
On Scratch's side, there's a server running at But here's a bit tricky to answer: How cloud variables work? https://mv-ezproxy-com.ezproxyberklee.flo.org/ with 2 main parts: a database which stores the cloud variables and a WebSocket server that's used to receive and send variables from and to users.
When the browser loads a project, it connects to said WebSocket server and performs some authentication stuff.
After that, the server sends the states of every cloud variable in the project, and the player simply sets those cloud variables to the values the server sent (also when the server sends cloud variable updates).
When the projects sets a cloud variable, a message is sent to the server saying to set that cloud variable to the value the variable was set to.
- scratcher2286
-
79 posts
How does Scratch work?
On Scratch's side, there's a server running at But here's a bit tricky to answer: How cloud variables work? https://mv-ezproxy-com.ezproxyberklee.flo.org/ with 2 main parts: a database which stores the cloud variables and a WebSocket server that's used to receive and send variables from and to users.
When the browser loads a project, it connects to said WebSocket server and performs some authentication stuff.
After that, the server sends the states of every cloud variable in the project, and the player simply sets those cloud variables to the values the server sent (also when the server sends cloud variable updates).
When the projects sets a cloud variable, a message is sent to the server saying to set that cloud variable to the value the variable was set to.
https://github.com/LLKYou can read all the code for scratch in an understandable format here:
The code specifically for the blocks is here: https://github.com/LLK/scratch-vm/tree/develop/src/blocks
Basically scratch looks for an event block, then find then looks for a bit of JSON which says “next” followed by the block id. It then calls a JavaScript function to run that block, then it looks for another “next” in the JSON the runs that block and so on.
The green flag (And all the other buttons on scratch) has a JavaScript event listener which waits until the flag is clicked.
Thank you for that! Now I can make my own Scratch replica.
I am closing this topic now.
- Discussion Forums
- » Open Source Projects
-
» How does Scratch work?