Category:Events

Triggers a sequence of blocks to run when a specific sprite is clicked.

(Opens YouTube in new tab)

How To Make A Sprite

Sometimes code should only be run if an event happens. In this case, when a sprite is clicked, the blocks attached under the event block will begin to run sequentially. If the costume block is used here, the code will run whenever any sprite with the matching costume is clicked.

This block has a drop-down menu with “when” and “while” options. “When” a sprite is clicked, the code will only run once. “While” a sprite is clicked, the code will run over and over again until the sprite stops being clicked on.

Examples

Example 1

The paintbrush will change the background color each time it is clicked.

Example 2

The pencil will grow as long as it is being clicked on.

Example 3

Click on the cupcake to move it away from the flies, and click on the flies to swat them away.

Parameters

NameDescription
when/while Determines if the code is run when the sprite is clicked (runs once at a time) or continuously while the sprite is clicked
sprite The sprite or sprite group being clicked

Tips

  • If you want something to happen only to the individual sprite being clicked, use the this / other sprite block in any of the following actions.

Found a bug in the documentation? Let us know at documentation@code.org