(Redirected from Switch to Costume () (block))
Switch Costume to () | |
switch costume to ( v) | |
Category | Looks |
Type | Stack |
The Switch Costume to () block is a Looks block and a stack block that changes its Sprite's costume to a specified one.
This block is used whenever a sprite must switch to a specific costume (instead of the Next Costume block, which only switches to the next costume in the costume list). A variable (or any reporter block) containing a number or the name of a costume can be dropped in. If a non-whole number is input into the block, the number is rounded.
The stage uses backdrops instead of costumes, which can be switched with the Switch Backdrop to () block.
History
In very early, unreleased beta versions of Scratch, this block was called Look Like (). This original name is also the reason why its Squeak method was titled lookLike:
.
Example Uses
Because of its simplicity, this block does not have a specific list of main uses — it is simply used to change the costume of a sprite.
Some common uses are as follows:
- Simply changing a costume
when I receive [Broadcast v] switch costume to (costume2 v) go to x: (0) y: (0) show
- Changing a costume as part of a sequence
wait until <(variable) = [50]> change x by (10) switch costume to (costume1 v)
Switching to the Previous Costume
There is no Previous Costume block in Scratch. The costume number can be used instead to calculate the previous costume:
switch costume to ((costume [number v]) - (1))
If the sprite doesn't have a costume named "previous costume", then the following block will also switch to the previous costume:
switch costume to (join [previous costume] [])
Switching to the Last Costume
The first costume's costume number is 1. When switching to a costume number lower than 1, for example 0, -1, or -2, Scratch will wrap around to the end of the costume list. This is a trick that can be used to go to the sprite's last costume:
switch costume to (round (0))
Workaround
- Main article: List of Block Workarounds
This block can be replicated with the following code:
repeat until <(wanted costume #) = (costume [number v])> next costume end
However, it is normally much faster to use the original block, and if there are many costumes, the sprite will appear to "flash" between the different costumes.
Things Worth Noting
When a Costume has a Number for its Name
When at least one of the costumes' names is a number and you pass that number to this block, the block's behavior will be different depending on the input's type:
- if the input is a number-type value (e.g a number returned by a
(() + ())
), the block will switch to the costume with that costume number. - otherwise, or if it's a string-type value (e.g a number joined together with a
(join [] [])
block), the costume will switch to the costume named that number.[1]
So, switch costume to (round (5))
will switch to costume number 5, but switch costume to (join [5] [])
will switch to the costume that has the name "5".
Effects of Too Many Layers on a Costume Switch
Sometimes, a costume will not switch to the desired costume. This is usually an effect of the use of layers. Large amounts of layers have a tendency to create immense lag, and therefore on less powerful computers/machines, this can cause a delay between switches in costume appearance.
See Also
References
For sprites |
Say () for () Seconds • Say () • Think () for () Seconds • Think () • Switch Costume to () • Next Costume • Switch Backdrop to () • Next Backdrop • Change Size by () • Set Size to ()% • Change () Effect by () • Set () Effect to () • Clear Graphic Effects • Show • Hide • Go to () Layer • Go () () Layers • Costume () • Backdrop () • Size
|
For the Stage |