Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Make "My Blocks" - Part 1

Make "My Blocks" - Part 1

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

     

    Prerequisite

    • Working with Blocks

     
     

    Introduction

    When you write a Scratch program, you can choose from many blocks provided by the playground. However, you can also make your own blocks. To do that, you need to take 3 steps:

    1. Define the new block: you need to tell the system what this new block looks like;
    2. Implement this new block: you need to tell the system what this block does;
    3. Use this new block: you will be able to drag this new block from the flyout into your program.

     
     

    A Complete Example

    Let’s go through these 3 steps in a complete but simple example.

     

    Define a New Block

    To define a new block, you can go to the “My Block” category, and click “Make a Block”. You can type any name for your block, such as “run”, then click “OK”. You will see a new “run” block in the flyout, and also a “define run” block in the coding area.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/03ef3445-d7f8-4d9e-8d6a-b5428514cf61.gif" width="1100" style="border-radius: 5px; border: 1px solid #29622d;">

     

    Implement the New Block

    Now we need to add other blocks into the “define run” stack, just like how you would build any stack of code. For example, suppose we want to make the sprite move right 5 steps whenever we use the “run” block, then it will look like this:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/14e4a3a0-064e-4e17-9219-0694b364cffe.png" width="160" style="">

     

    Use the New Block

    Now our block is defined and also implemented, we can start using it in other parts of the program. For example, whenever the sprite is clicked, we make the sprite run:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/480a0a81-0614-40c3-aeeb-0cce510dfa42.gif" width="1100" style="border-radius: 5px; border: 1px solid #29622d;">

    Whenever the system sees the “run” block, it will jump to the “define run” stack, and go through all the blocks in that stack.

    That’s an example of making and using a very simple block. Below let’s look at some different ways to define and use new blocks.

     
     

    Define a Block with Input Parameters

    Many blocks provided in the playground can take input parameters. For example, the “say” block takes one input, so you can use it to say different things. You can make your own block take input parameters as well.

    When you define the block, you can add 3 types of inputs:

    1. Number or Text: This input will be oval-shaped, and it accepts a number or a text.
    2. Boolean: This input will have triangle tips on the 2 sides, and it accepts any boolean block.
    3. Color: This input will be a color value.

    Now let’s change the “run” block to take 3 inputs named “times”, “pen down” and “color”:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/3eca31cb-42f8-4aff-b44a-b3b41910e429.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">

    As shown, after changing the definition, the “define run” block now carries 3 input blocks for you to use inside this stack. Note that you can only use them inside this stack.

    For example, we can use the “times” input to control how many steps we move, use the “pen down” input to control whether to put down the pen or not, and use the “color” input to control the color of the pen:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/bb7f8c49-5014-4dde-a6f9-48db74a1e066.gif" width="350" style="">

     
     

    Use a Block with Input Parameters

    You can use the new “run” block just like any other block. You just need to set the value of the 3 input parameters. For example, if you set the first input to 4, then the sprite will move 4 steps.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/af0ee50d-c63d-4d0f-8438-723f1bc41685.png" width="1000" style="">

    This is what you get when clicking on the sprite:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a6a1520f-3863-4748-96fe-89c6f6cb9ca5.gif" width="500" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    How to Delete My Blocks

    To delete my block, you have to find where you are using this new block, and delete all of them, then you can delete the “define” stack. If the new block is still in use somewhere, then you can’t delete the “define” stack.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/6e6671da-a92f-4097-9cbf-a863eec01b65.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">

     
     

    Change the Color of My Blocks

    To change the color of my block, click on the “Set my block’s color” button in the “My Blocks” category. my blocks color.PNG

    A pop-up window will allow you to select the color of your block. Click “change” to set it.

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/486b07f4-8b4b-42b8-a1b0-d578129b3829.PNG" width="200" style="">

    Here is a demo:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/7b2fe420-80c8-4a43-bb4b-be99bd805cf9.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">
     

     
     

    See Also

    • Make “My Blocks” - Part 2
    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode