(Redirected from When () Clicked (block))
|When This Sprite Clicked|
The When This Sprite Clicked block is an Events block and a Hat block. Scripts that wear the block will activate once its sprite or clone of the sprite is clicked. Contrary to its definite name, the block will also execute the clone's script when the clone is clicked on.
Clicking on transparent areas of the sprite does not trigger this event, except for transparent areas surrounded by using the hollow rectangle and oval tools in the bitmap editor.
If a sprite is has been hidden by the hide block, when its location is clicked on, the script under the When This Sprite Clicked block will not activate.
In the stage, this block is called When Stage Clicked.
when Stage clicked :: hat events
In Scratch 1.4, this block was called When () Clicked. It was automatically filled in with the name of the sprite it was placed on.
In Scratch 2.0, its name was changed to When This Sprite Clicked, likely to make the block name consistent for all sprites. In early versions, it was called When I Am Clicked, but this was changed for unknown reasons.
- Making buttons
when this sprite clicked broadcast [open menu v] //an example button that opens a menu
when this sprite clicked switch backdrop to [meadow v] //changing backdrops
- Interacting with objects
when this sprite clicked repeat (20) change [whirl v] effect by (5) end repeat (10) change size by (-10)
- Input controls
when this sprite clicked say [Hello!] for (2) secs ask [How are you feeling today?] and wait if <(answer) = [Happy]> then say [That's good!] for (2) secs
when this sprite clicked set size to (90)% wait (0.5) secs set size to (100)% broadcast [Menu v]
- Main article: List of Block Workarounds
This block can be replicated with the following code:
when gf clicked forever wait until <not <mouse down?>> wait until <mouse down?> if <touching [mouse-pointer v]?> then . . . end
when gf clicked forever if <<mouse down?> and <touching [mouse-pointer v]>> then . . . wait until <not <mouse down?>> end
when [timer v] > (0.1) wait until <<mouse down?> and <touching [mouse-pointer v]?>> . . . wait until <not <<mouse down?> and <touching [mouse-pointer v]?>>> stop [this script v]