Help the wiki!

The Scratch Wiki is made by and for Scratchers. Do you want to contribute?

Learn more about joining as an editor!

See discussions in the Community Portal

When Backdrop Switches to () (block)

(Redirected from When Scene () Starts (block))

When Backdrop Switches to ()
2.0 When Backdrop Switches to ().png
Category Event
Type Hat
Introduced in 2.0

The When Backdrop Switches to () block is a Event block and a Hat block. Scripts that wear this block will be invoked once the specified backdrop has been switched to on the Stage.

Contents

Example Uses

  • Starting a level
switch backdrop to [level1 v]
when backdrop switches to [level1 v] //in a sprite
go to x: (0) y: (0)
  • A game over message
switch backdrop to [game over v] // in Stage
when backdrop switches to [game over v] // in a sprite
hide
  • Switching among menus
switch backdrop to [menu 3 v]
when backdrop switches to [menu 3 v] //when "menu 3" is opened
go to front //so the menu item displays in the front
show //this opens up the menu

Recursion

This block can use recursion to continuously run scripts. An example is as follows:

when backdrop switches to [snow storm v] //a background switch must first be triggered to begin the recursion
. . .
switch backdrop to [sunny day v] //which will trigger the next script

when backdrop switches to [sunny day v]
. . .
switch backdrop to [snow storm v] //starts the cycle over

Workaround

When the backdrop changes, sprites with the When Backdrop Switches to () block, and the attribute as the backdrop being changed to (meaning the selected backdrop within the block is what is being switched to), the sprites will react and run their scripts beginning with this hat block. Broadcasts can be used to replicate this situation, though there may be a miniscule delay due to an extra block being added. The following is a workaround, often used in Scratch 1.x:

switch backdrop to [valley v]
broadcast [valley v] 

when I receive [valley v]
. . .

See Also

  • This page was last modified on 11 February 2014, at 05:14.