Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » What does the define block do ?
- hani2018
-
100+ posts
What does the define block do ?
I’m having trouble understanding what the define block in the ‘my blocks’ action does when I had trouble moving the sprite to the left I used the my blocks to create a easy ‘move left’ block but also came with a ‘define’ block. But what does the define block do ?

- Flipped_
-
500+ posts
What does the define block do ?
The “define” block is the hat block you use to define a My Block. All blocks under the My Block definition is what runs when you run the corresponding My Block. For example -
- codeman1044
-
1000+ posts
What does the define block do ?
The “define” block is the hat block you use to define a My Block. All blocks under the My Block definition is what runs when you run the corresponding My Block. For example -
That's the basics of the custom blocks. The define block is just where you put your code to tell the program how to run your block. I have an example here (read this post first):
https://scratch.mit.edu/projects/293658088/editor/
There's a list of instructions explaining what the code does, but if you don't want to worry about it, don't.
Here's the use of the custom block:
To reduce repetitive chunks of script.
To make users able to customize the game easier, like making a custom setting.
To have a script chunk adapt to an input (check out the link)
The purpose of the define block is telling what the custom block to do. It's like the actual scratch program: no code, nothing happens. You have to tell he computer what to do, and how to do it.
There are 3 different options for custom blocks: text box, a text/number input, or a boolean input. All of those are (kind of) reviewed in the link above.
The option to run without screen refresh just slows the fps of the scratch game to the point where the code can run within one frame. Useful for some cases, but not others.
When using a define block, if you have inputs, those input spots are like variables in a way: you click and drag them from the define block into the attached script where you want them (examples given in link).
If I missed something, or didn't explain something well, let me know!
- deck26
-
1000+ posts
What does the define block do ?
Also worth knowing that a custom block can run much faster than other code if you tick the ‘no screen refresh’ box. As long as there are no wait blocks or any loops that take too long to complete in a short time this can make a huge difference to your project. But if it can't complete in the specified time limit you'll get horrible lag so test before setting the no screen refresh option.
- Discussion Forums
- » Help with Scripts
-
» What does the define block do ?