Reputation: 341
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!
Upvotes: 4
Views: 7329
Reputation: 11
Probably, the intended meaning is a custom block. Click on the “My Blocks” category and “Make a Block” to create one:
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.
Upvotes: 0
Reputation: 11
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 :)
Upvotes: 1
Reputation: 125
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):
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.
Upvotes: 1
Reputation: 61
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
Upvotes: 1
Reputation: 31
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':
Upvotes: 3
Reputation: 144
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.
Upvotes: 10
Reputation: 138
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!
Upvotes: 6