How do I duplicate a custom code block in Scratch?

88 Views Asked by At

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"?

1

There are 1 best solutions below

0
Ruud Helderman On BEST ANSWER

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.