When This Sprite Clicked (block)

(Redirected from When () Clicked (block))

When This Sprite Clicked
2.0 When This Sprite Clicked.png
Category Control/Event
Type Hat
Introduced in 1.0

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.[1]

In the stage, this block is called When Stage Clicked.


when Stage clicked :: hat events
The When Stage Clicked block.

History

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.

Example Uses

  • 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
  • Menus
when this sprite clicked
set size to (90)%
wait (0.5) secs
set size to (100)%
broadcast [Menu v]

Workaround

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

or

when gf clicked
forever
if <<mouse down?> and <touching [mouse-pointer v]>> then
. . .
wait until <not <mouse down?>>
end

or

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]

References

  1. "Hide (block)"
  • This page was last modified on 27 July 2017, at 18:17.