0

I've got a custom code block that I've written in Scratch:

Scratch Decimal to Binary

I want to duplicate my code block so that I can have a second version that is slightly different instead of having to create a whole new block from scratch manually.

Is it possible to duplicate any of "My Blocks"?

4
  • Duplicating the 'body' of the custom block is easy and would already save you a lot of work. You'd only have to create a new 'head' manually. Would that be acceptable to you? Commented Feb 11, 2024 at 14:05
  • @RuudHelderman Ah. Yes. That's useful. That's perfect. Thanks. You're welcome to post an answer to that. It's exactly what I wanted. Commented Feb 11, 2024 at 14:24
  • 1
    How "slightly" is your new block different from the original? I would strongly suggest to NOT duplicate a block, but add a parameter and implement that variation within one block. Commented Feb 11, 2024 at 20:41
  • @VladFeinstein Good advice. In fact, I don't recall ever feeling the need to duplicate a custom block within the same sprite (though across sprites, I consider it common practice). However, an additional parameter to change the behavior of a custom block may lead to overly complex code (typically with too many if-then-else blocks); Scratch has no higher-order functions, interfaces or homoiconicity. Commented Feb 11, 2024 at 21:56

1 Answer 1

1

Duplicating the 'body' of the custom block is easy and would already save you a lot of work. You'd only have to create a new 'head' manually.

Steps to take:

  • Right-click on the first block underneath the original custom block's hat block (in your case: the block "set binary to 0").
  • From the context menu, select 'Duplicate'. This will duplicate the block and everything below it, i.e. everything except the hat block.
  • Create a new custom block. Make sure it has the same parameters as the original custom block.
  • Drag and drop the duplicated blocks under the new custom hat block.

Edit: There's actually a way to duplicate both head and body. It makes use of the fact that dragging a block to another sprite will duplicate it. Obviously it does demand you to rename the duplicate; having two custom blocks with the same name within the same sprite is a very bad idea.

As you may have guessed, your project needs at least two sprites to perform this trick. If your project only has one sprite, then just create a temporary dummy sprite, and delete it when done.

Steps:

  • Go to the code of the sprite with the custom block you'd like to duplicate; let's call this sprite A.
  • Drag the custom block (the entire script) to the panel at the bottom right of the project editor, and drop it on sprite B.
  • Go to the code of sprite B. Notice a copy of the custom block is present there.
  • Rename the custom block (to avoid a conflict with the original custom block).
  • Drag the custom block back to sprite A.
  • Delete the custom block from sprite B (or delete the entire sprite if it was just a dummy).
  • Go to the code of sprite A. Notice both custom blocks are present there. If you see only one, drag it aside a bit; it may be overlapping and hiding the original custom block.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.