

Make sure you drag any blocks beneath these back to the original script. ask Should the cat meow or scream when it's nipped by the crab? and wait.The blocks you need to move are the following: Now drag the blocks that run that routine to the 'hat' for your custom block. I'm going to call it: 'User defines cat sound'. Click the Make a Block button, and name your first block. Make sure you've got the cat selected, and go to the More Blocks section. Let's create two custom blocks: one for the routine that asks the user to define what the cat will say, and one for the routine that makes the cat react to being caught by the crab. Here's what the cat scripts look like now: The cat sprite currently has quite a lot of blocks in its main script, so let's apply this principle to that. Creating a Custom Block to Shorten a ScriptĪnother way you can use custom blocks is to replace large routines in your scripts, making your scripts shorter and easier to manage. If you want to make a custom block apply to all of your sprites, create it in the Stage.
How to create your own game on scratch code#
This has only reduced the code by three lines in that script, but you can see how if you were using larger routines or repeating them more often, for different sprites perhaps, it would make things more efficient. The script will now have 11 blocks of code instead of 14: Once you've done that, edit the script with those two repeating blocks in it so that the two blocks are replaced by your custom block each time. These will be the wait 1 secs and change Timer by -1 blocks. To define this block, you need to add the blocks it will replace beneath that 'hat'. You'll now see a new script 'hat' called define Count down every second (or whatever you've called it): You'll be presented with the New Block dialog box: Select the Stage and click on More Blocks. This isn't a lot of repeating code, so in a real project you might choose to leave it as is, but for the purpose of this tutorial let's replace it with a custom block. In this project the main script for the Stage includes some repetition of two lines: Rename it and you're good to go! Creating a Custom Block to Avoid Repetitionįirst you need to identify where a custom block would make your scripts more efficient. Scratch will save a duplicate of my project as a new project in your account. Log in to Scratch and go to the page for my project on animations.Ĭlick the See Inside button to view the project: In the toolbar, click File > Save as a copy: Make sure you've clicked the See Inside button so you can see the workings of the project.

Open Scratch and go to the project you want to duplicate. Here's how you do each of these (you'll only need to do one).
How to create your own game on scratch series#
You're now most of the way through this beginner's series on Scratch.
