How to use the "My blocks" feature?

id: 626705

category: Help with Scripts

posts: 12

I want to know how to use the “My blocks” feature? I feel like it could really help me, but I just don't know how!
Any help appreciated al lot

Advantage_coding wrote:

I want to know how to use the “My blocks” feature? I feel like it could really help me, but I just don't know how!
Any help appreciated al lot
Thanks for asking!

The my blocks section is essentially a category where you decide (for your project) what blocks exactly do you want to put there. It's like a sandbox but for scratch.

As an example, say you wanted to make a project. In this project, you would want your player to jump.
You could do:

when [whatever you want your key to jump to be v] key pressed
change y by (5) // 5 is an example, you can set it to how high you want to jump.
wait (1) secs // like i said, also an example
change y by (-5) // 5 is how high you jump in this example. JUST MAKE SURE YOU SET IT TO THE NEGATIVE OF THE JUMP HEIGHT!

But that takes up space, so you can just package it in a block (in this example, called “jump”)

define jump
if <key [like i said, your jump key v] pressed?> then
change y by (5)
wait (1) secs
change y by (-5) // all these comments are the same as the last example
end

And then do this to let your player jump:

when green flag clicked // or whenever you want your player to jump
forever
jump :: custom blocks
end

And that is essentially it for now.
Thank you so much! I have a way better understanding now
deck26 deck26 loading
https://en.scratch-wiki.info/wiki/My_Blocks

As well as tidying up code and making it more readable custom blocks have advantages.

- a custom block called by a sprite or clone is only run by that sprite/clone whereas all clones will act on a broadcast which would be another way to split code

- you can use the ‘no screen refresh’ option for speed

- you can pass parameters so eg you can draw a circle at a specified location and a specified size just by entering the correct values in a the custom block call
what do you mean by ‘no screen refresh’?
RT_Borg RT_Borg loading

Advantage_coding wrote:

what do you mean by ‘no screen refresh’?
Hi Advantage_coding,

Many of the blocks in scratch cause a script to pause for 1/30 of a second to redraw. For example, if you do a series of moves or costume changes, you typically want to see each change on the screen before then next one.

But sometimes you want to do a lot of operations all at once, without slowing down or having the player see. An example would be testing whether a moving sprite is colliding with a wall, so it can change directions. You might move forward, test and discover you're now touching (inside) the wall, and then quickly undo the move (move back in the opposite direction). You don't want the player to see that test and maybe back out of a collision, so you'd want to do it “without screen refresh.”

When you make a custom block, there's a checkbox where you can choose “without screen refresh” for the block.

– RT_Borg
KaaBEL_sk KaaBEL_sk loading
I would also mention advantage of using stop this script in my blocks.
stop [this script v]

Sometimes a script inside loop requires to stop before the end of loop, but cotinue other code. Or it can be used as end the loop instead of puting more conditions in repeat until, there can be anywhere in the script if with stop this script.

I also use my blocks for comments (as I saw somewhere else). Those are composed in the sript, and stay even after backpacking the script.
define // (comment)

\// [here's stuff commented]
isaacxcode isaacxcode loading

Advantage_coding wrote:

I want to know how to use the “My blocks” feature? I feel like it could really help me, but I just don't know how!
Any help appreciated al lot

To make it simple, when you make a block you get two things:

define 

and in the my blocks section you will see another block.

Now, the block that you see in the my blocks section, is what will trigger what is inside of the Define “Your block name”

define 

For example, in the Define block, if I were to put in a change x by 10
when green flag clicked
forever

end
(The block)

So basically what this does is "When the flag Is clicked, forever, trigger your block. Inside of the block is a change x by 10. So you will forever change x by 10.
MineTurte MineTurte loading

isaacxcode wrote:

Advantage_coding wrote:

I want to know how to use the “My blocks” feature? I feel like it could really help me, but I just don't know how!
Any help appreciated al lot

To make it simple, when you make a block you get two things:

define 

and in the my blocks section you will see another block.

Now, the block that you see in the my blocks section, is what will trigger what is inside of the Define “Your block name”

define 

For example, in the Define block, if I were to put in a change x by 10
when green flag clicked
forever

end
(The block)

So basically what this does is "When the flag Is clicked, forever, trigger your block. Inside of the block is a change x by 10. So you will forever change x by 10.
Please don't necropost; especially when it already seems as if this topic was resolved. Thanks!

Necroposting is when you post on an old topic either not adding anything or adding irrelevant information. In your case you were just saying what was already said.
there are 3 options in the my blocks window the add an input (number or text) and add an input (boolean) and add a label there is also a run without screen refresh option