Discuss Scratch

scrathchermen
Scratcher
9 posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

Hello Scratch community,

I’ve been exploring custom blocks lately and I’m curious about how to use them more effectively in my projects. I understand they help organize code and make projects cleaner, but I’d like to learn more about how to work with different types of inputs like numbers, strings, and booleans.

It would be great to hear about ways to make custom blocks flexible and reusable, and maybe some tips on avoiding common mistakes. Also, I’m interested in how custom blocks compare to message broadcasting and when one might be better than the other.

Any examples or advice on these topics would be really appreciated. I’m hoping to improve my coding style by making better use of custom blocks.

Thanks in advance!
KangaCoder
Scratcher
1000+ posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

Here's a nice article about custom blocks which has stuff about possible uses.
Bitebite12
Scratcher
1000+ posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

I will share what I know.

IMPUTS
They function just like an imput on
move () steps
would.

Lets look at this block as a custom block.

define move (steps) steps
move (steps :: my blocks) steps :: movement

So, the imput can be used inside the define block.

This is useful, becuase you dont need a block for each imput.

BOOLEANS

These can be used like imputs, but for booleans!
Example:

define walk (steps) steps <boolean>
if <boolean> then
walk (steps) steps :: motion
end

In them you can put any boolean!

RUN WITHOUT REFRESH

Who knew a little check mark could change everything?

Scratch runs at 30 fps (max). This means
forever
change [score v] by 1 :: variables
end
will change ‘score’ by 30 a second at max fps.

But run without screen refresh…

As. Fast. As. Scratchingly. Possible.

Like turbomode!

This is a lifesaver for any sort of pen rendering. You shouldn’t have to wait 1 minute for 1 frame! Sure, its laggy. But its worth it.
scrathchermen
Scratcher
9 posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

@Bitebite12 Thanks a lot for your response!

But, if what they can do is make another string activate, what's the difference between custom blocks and message blocks? And how can I set a specific value for imputs or to use booleans more efficiently?

Thanks for your explanation and effort!

-Scrathchermen

IceCreamTub
Scratcher
1000+ posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

real quick

scrathchermen wrote:

@Bitebite12 Thanks a lot for your response!
The @ symbol does nothing on the forums, it will not send out any sort of notification to anybody.

SidewaysCoder
Scratcher
500+ posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

First, do not use AI to make posts on these forums. It does not promote constructiveness at all.

Let's say you have a repeated set of code blocks. It can get pretty repetitive every time you have to copy the code blocks, and it gets worse when you have to change the code blocks because now you have to update every single set of code blocks.

Custom blocks allow you to use one block in order to use an often repeated set of code blocks. You can add inputs into custom blocks, known as parameters. And, when you need to change something, you just have to edit the block definition.
Quantum-Cat
Scratcher
1000+ posts

Unlock the Power of Custom Blocks! How Do You Use Them Effectively in Scratch?

scrathchermen wrote:

(#4)
@Bitebite12 Thanks a lot for your response!

But, if what they can do is make another string activate, what's the difference between custom blocks and message blocks? And how can I set a specific value for imputs or to use booleans more efficiently?

Thanks for your explanation and effort!

-Scrathchermen

Because they have different behaviours, they have different use cases.
  • When you create a custom block, it can only be used in the sprite it was created in (or the stage if it was created in the stage). Broadcasts are used to communicate across different sprites.

  • You can define custom blocks to have inputs:
    define draw square (width) from (x) (y)
    go to x: (x) y: (y)
    pen down
    repeat (4)
    move (width) steps
    turn cw (90) degrees
    end
    This is difficult to do with broadcasts because they can't accept inputs directly, and you would have to do it using variables (I would need 3 new variables to do this). If a custom block doesn't have parameters defined, it is similar to a broadcast, but there is one more thing that custom blocks can do that broadcasts can't…

  • When you make a custom block, you can select a checkbox called “run without screen refresh”. In simple terms, this makes code run faster. To be more accurate, you first need to note Scratch runs at a maximum of 30 FPS. When code causes Scratch to render the next frame on the stage, we say it “refreshes the screen”, and this generally happens at the end of loops and with wait blocks. Try and run the code above above and you will see each side being drawn with about a 1/30 s delay.

    If you make the block run without screen refresh, Scratch will attempt to run all of the code in the custom block definition without updating the screen and without the delay at the end of loops, so the square will be drawn all at once.

Last edited by Quantum-Cat (May 22, 2025 09:13:53)

Powered by DjangoBB