Discuss Scratch

scratcher2286
Scratcher
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.
PyraEthan12
Scratcher
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
Scratcher
79 posts

How does Scratch work?

PyraEthan12 wrote:

Scratch blocks are a sort of JavaScript which is used in block form. While the blocks are not “real” programming.
I know that those blocks are just simple JSON data. But how does the interpreter, Scratch VM, runs those blocks?
-_Puppy_-_Vibes_-
Scratcher
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.
CST1229
Scratcher
1000+ posts

How does Scratch work?

-_Puppy_-_Vibes_- wrote:

(#4)
You stack the blocks to make an algorithm. It is easier than it looks! Watch this for the basics.
They said “How does Scratch work?”, not “How do I use Scratch?”.
billy2215
New Scratcher
2 posts

How does Scratch work?

it is just magic.
why do you ask?
PyraEthan12
Scratcher
1000+ posts

How does Scratch work?

billy2215 wrote:

it is just magic.
why do you ask?
It’s not “magic” it’s programmed to function.
scratcher2286
Scratcher
79 posts

How does Scratch work?

billy2215 wrote:

it is just magic.
why do you ask?
It is NEVER magic that's why I asked.

However I don't know what happens behind my project when I run it.

My question explaination:
See these blocks:
when green flag clicked
say [Hello]
wait (2) secs
say []
I know what happens: When the green flag is clicked, the cat says Hello indefinitely and waits and says nothing again.
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
Scratcher
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.
CST1229
Scratcher
1000+ posts

How does Scratch work?

scratcher2286 wrote:

But here's a bit tricky to answer: How cloud variables work?
On Scratch's side, there's a server running at 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
Scratcher
79 posts

How does Scratch work?

CST1229 wrote:

scratcher2286 wrote:

But here's a bit tricky to answer: How cloud variables work?
On Scratch's side, there's a server running at 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.

RalphJP wrote:

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.

Thank you for that! Now I can make my own Scratch replica.
I am closing this topic now.

Powered by DjangoBB