انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

Define a block

Section 11: My Blocks: make a new blockLesson 11.1 · ⏱ 8 min

In My Blocks make a block with a name you choose, like “square”, and put its steps under define once. After that, use the new block whenever you like, like any block in the program.

🧩 Define “square”
Blocks: define (square), pen down, repeat (4), pen up
🧩 The program
Blocks: when 🚩 clicked, erase all, hide, pen up, go to x: (-150) y: (-30), set pen size to (4), (square), change x by (100), (square), change x by (100), (square)
Three squares, with only three “square” blocks
Three squares, with only three “square” blocks
📌 Note
Think: how many blocks would you need without “square”? And if you wanted to make all the squares bigger, how many places would you change now? Only one: inside define.

📌 Another example: a “star” block

We define the star once, then use it 3 times with only three blocks instead of 3 × 4 blocks.

Blocks: define (star), pen down, repeat (5), pen up
Blocks: when 🚩 clicked, erase all, hide, point in direction (90), set pen color to (orange), set pen size to (3), go to x: (-190) y: (0), (star), change x by (140), (star), change x by (140), (star)
Three stars
Three stars
✍️ Practise
Make a “line” block that draws a line 100 long, and use it 3 times.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Make a “triangle” block and draw a row of 4 triangles.

👀 Show the solution
Blocks: define (triangle), pen down, repeat (3), pen up
Blocks: when 🚩 clicked, erase all, hide, point in direction (90), go to x: (-200) y: (-40), repeat (4)
The result on the stage
The result on the stage
Medium

Make a “jump” block (up, then down), and use it inside repeat 3.

👀 Show the solution
Blocks: define (jump), change y by (50), wait (0.25) seconds, change y by (-50), wait (0.25) seconds
Blocks: when 🚩 clicked, go to x: (0) y: (0), repeat (3), say (I jumped 3 times!) for (2) seconds
After 3 jumps
After 3 jumps
Hard

Make a “circle” block and draw 5 coloured rings with it, overlapping.

👀 Show the solution
Blocks: define (circle), pen down, repeat (36), pen up
Blocks: when 🚩 clicked, erase all, hide, point in direction (90), set pen size to (4), go to x: (-120) y: (0), set pen color to (blue), (circle), go to x: (-30) y: (0), set pen color to (red), (circle), go to x: (60) y: (0), set pen color to (green), (circle), go to x: (-75) y: (-40), set pen color to (yellow), (circle), go to x: (15) y: (-40), set pen color to (purple), (circle)
Five rings
Five rings
Finished the lesson? Mark it so your progress counts.