4

I'm going through a "Learn to Program with Scratch" book with my kid. One of the exercises is asking to create a "function block" that uses some simple formula. They don't explain what is "function block" in the book or I might've missed it. I couldn't find any info about it either. Could anyone tell me what is this and may be give an example? Thanks!

user1298416
  • 341
  • 4
  • 11

7 Answers7

10

A function block is actually a custom block. This is the purple More Blocks palette of scratch. In the palette, you can click Make a Block which allows you to define your own block/method. You can name the block and also click on options to add parameters so you can insert parameters. You can drag the dark blue parameter in the define header of the block into the relevant block for a variable. E.g. Define[DrawSquare (size)] // where (size) is the blue circle and parameter. repeat (4) move (size) steps turn 90 degrees

To put the parameter in, you must drag the (size) in the definition header into the white space for move () steps.

Once you have created your block, you can add the block to the program from the same palette. You can insert your arguments in the parameters which are the white spaces.

Knd6060
  • 144
  • 2
6

I believe that you are looking for http://wiki.scratch.mit.edu/wiki/Custom_Blocks. It seems that functions are called "Custom Blocks" in Scratch.

As for the concept of a function in general http://www.webopedia.com/TERM/F/function.html should do the trick.

There are examples on the first link.

Good luck!

Stal G
  • 128
  • 1
  • 7
3

Here is an example:

This block will allow the sprite to say something for an amount of time. It also stores the data in list 'say':

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Sean
  • 31
  • 3
  • Welcome to Stack Overflow! Please feel free to take a [tour](//stackoverflow.com/tour) of the site, and if you need additional help with the site, check [this](//stackoverflow.com/help) out. Oh, and if you ever run into issues that the help page doesn't cover, feel free to ask on [meta](//meta.stackoverflow.com/). – Claudia Jun 20 '17 at 15:45
1

A function is a block to use to "compile code". So, instead of writing

move 10 steps
turn 15 degrees
wait 1 second
say hi for 2 seconds

repeatedly, you can do this:

define useless function
move 10 steps
turn 15 degrees
wait 1 second
say hi for 2 seconds

Then, all you got to do is to call the function useless function

Account_2
  • 53
  • 6
1

A function block is a custom block in Scratch. It's very efficient for some cases, including pen (If you try it out, I used the "run without screen refresh" for the instant drawing):

pic But basically it saves more time than making variables and setting all of them to the desired amount before drawing the square.

Same thing for booleans.

stonefish
  • 115
  • 8
1

A function block in Scratch is like the other blocks that are found, except that you are the one who decides what it does. You can input values in the block. For example, if you want to make a block that can draw figures, you can allow the person to choose the amount of sides the figure has. Then, by putting the answer into the block, you can draw the figure.

    Eg. Ask for number of sides
    Custom block:  Drawsides(answer goes here)
    Drawsides will draw a figure according to the number of sides. 

In short, custom blocks help you to refrain from writing the same code over and over again by defining it in the block, and then using the block. You can also choose not to have input values in the custom block. Hope this helps :)

0

Probably, the intended meaning is a custom block. Click on the “My Blocks” category and “Make a Block” to create one:

My Blocks

Make a block

The custom block screen will appear, and it should be pretty simple from there.

Note: The “Run without screen refresh” checkbox makes the code run really fast, especially code that uses the pen extension.

Thanks for your time, Best Codes

Best Codes
  • 11
  • 3