Discuss Scratch

Capci360
Scratcher
9 posts

definition

how do you use definition and when would you need it?

define
Knight_In_Armor
Scratcher
100+ posts

definition

Hello! A definition, or a custom block as some call it, is a feature that allows you to create your own blocks, with other blocks, and somehow shortens your code. For example, if you are making a game where Scratch Cat says something and dances more than once, instead of:

whenclickedsayI love dancing!for2secsrepeat10move-2stepsmove2stepssayI love dancing!for2secsrepeat10move-2stepsmove2steps

You can replace it using definitions like this:

definedancesayI love dancing!for2secsrepeat10move-2stepsmove2steps
whenclickeddancedance

So basically, it acts as creating a new block, and then using that block. Hope I helped! Please follow, like and fav!
footsocktoe
Scratcher
1000+ posts

definition

Capci360 wrote:

how do you use definition and when would you need it?

define


Most of the time people use them it is not because they NEED to use them (although sometimes it is).

I use them to make my scripts easier for me to read.

Simple example: https://scratch.mit.edu/projects/151991854/
Capci360
Scratcher
9 posts

definition

thanks those really helped my programs will be a load easier for me to read

deenfoxx
Scratcher
100+ posts

definition

Capci360 wrote:

how do you use definition and when would you need it?

define

I'm surprised no one mentioned the fact that a custom block is the ONLY way you can set a specific sequence of blocks to execute without refreshing the screen. This is how you achieve turbo speeds of complex pen drawing and collision detection routines without drawing anything to the screen until after you are done with the code. I think that is what footsocktoe meant by people NEEDing to use them.

A good example can be found at this project someone else created…

https://scratch.mit.edu/projects/151078973/

Notice how when you start it draws the grass in the background (very slowly).

Here is mine with a simple addition of a custom block “drawSceneQuickly” set to “Run without screen refresh”.

https://scratch.mit.edu/projects/154371885/

Powered by DjangoBB