That way, the user doesn't have to repeat making that code multiple times, and this reduces lag as there are now less blocks.Ĭustom Blocks are also useful when a project relies on specific calculations multiple times. If a user has a long string of code they know they will be using a lot, it makes sense to use a custom block. These blocks can be dragged out and used in the definition just like variables. For example, a Scratcher could make a jump ():: custom block with a "height" input, and (height:: custom) will appear in the Define block. Number, String, and Boolean inputs can be added to custom blocks. Now, if the user changes their mind about how the sprite should vanish or appear, they need only change the block definitions.Ĭustom blocks also help by reducing project file size and allowing the user to disable screen refresh. This is especially useful in pen projects, where the same shape has to be redrawn multiple times: Without procedures, the Scratcher would have to duplicate the same sequence of blocks at each point, but by making "vanish" and "appear" blocks, they can write scripts in a way which matches how they think of them: This should happen at several points in the project. To vanish, the sprite should play a sound and repeatedly increase the ghost effect to reappear, it should repeatedly decrease the ghost effect. For example, suppose one wants a sprite to vanish and reappear. This is also true of Scratch's built-in blocks, like move () steps. If the block has been set to run without screen refresh, it will take only one frame to run.Ī block can also run itself from within itself, which is called Recursion, and can be used to solve many complex problems.Īpart from variables, procedures are the main kind of abstraction used in procedural programming they let Scratchers write scripts without knowing or thinking about the details of what each script does. Unlike Broadcasts, however, the code is run as if it was inserted where it was run from. The code under this block will be run whenever its corresponding block is run in a Script, similarly to Broadcasts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |