Make "My Blocks" - Part 2
CreatiCode last edited by
In the wiki page for Make “My Blocks” - Part 1, you learned the basics of making new blocks of your own.
This wiki page will introduce 2 advanced options for making your blocks.
“Screen Refresh” is also called “screen update”. It means the computer is updating what’s shown on the screen. Usually, the computer needs to erase everything on the stage from before, and then draw everything again. This happens very quickly, so it looks as if things are moving on the stage.
For example, suppose we move a sprite to draw some steps using the pen extension. This will take a few seconds to complete, because after each move, the computer needs to remove the drawing and the ball from the stage, and then redraw them with the updated ball position and steps. In addition, the information in the sprite pane below the stage is being updated as well, such as the x and y positions of the ball.
Suppose we do not need to show the animation of the ball, and we only need to show the final result on the stage, we can skip the screen updates to make the program run faster.
To do that, make a new block, and select the “Run without screen refresh” option.
Next, add all the blocks for making the drawing inside the “define” stack of this new block. When you run the program again, it will complete instantly because all the intermediate screen updates are skipped. Only the end result is drawn.
In summary, for both 2D and 3D projects, whenever you want your program to run faster, and you do not need to show the animations of the intermediate steps, then you should make a block to “wrap” all the steps, and select “run without screen refresh”.
By default, the new block you make will be a “stack block”. You can also change it to a “reporter block”, so that it can report a value as the result of running this new block.
For example, suppose you want to make a block that calculates the average value of 2 numbers, similar to the “+” block in the “Operators” category.
First, when you define this block, you should choose the “Round shape” option:
Next, in the “define” stack of this new block, you can set the result value of this block using the “Return” block from the flyout.
Now you should see that the new “average” block is round-shaped. It will return a number when you click on it: