In a program, you sometimes need to create multiple tasks, with each task having a sequence of code blocks. For example, a "Get Ready for Bed" program might include "Brush Your Teeth", "Change Your Clothes", and "Go to Bed" tasks. In programming a "function" is a module of code (usually with multiple code blocks) that performs a task. Functions allow you to divide programs into their various tasks, making it easier to create and manage large programs. The idea is similar to dividing an essay into paragraphs to make it easier to read, but with one key difference: a function may be used multiple times within a program. So if you have some code in a program that is repeated two or more times, it makes sense to make it into a function. There are two steps to using functions. First, we must define (or "declare") the function by giving it a name and putting some code blocks inside it. Second, when we want to have RoboBlocky execute the code in the function, we "call" the function, referring to it by its name. In RoboBlocky the code blocks to define and call functions are found in the Functions menu (the default name for a function is "do something", but we give each function its own unique and descriptive name):
Watch the video to find out more about defining and calling functions.
|
The createSquare function will use the robot to draw a square with side length 6 that is centered on the location of the robot. Use this function to draw two squares: one centered at (4, 4) and one at (9, 12). |
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
(
,
in
) in
|
|
![]() |
|
|
|||||||||||
|
|||||||||||