Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (Feb 2021)
Reason: unfinished
Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (Feb 2021)

It is possible to find how many costume numbers a sprite has in Scratch. This is a tutorial on how to find how many costumes a sprite has.

This can be used to debug sprites.


One method is to use the following script:

when gf clicked
switch costume to ((0) * (1)) // if one uses the join block with 0 and nothing, if a costume is called "0" it will not work
set [# of costumes v] to (costume [number v]) // it is a local variable
switch costume to (costume1 v) // Start costume.

Then, run the project and the variable should report how many costumes a sprite has.

This method works because the switch costume to ( v) block uses the formula:

(((input) - (1)) - (([floor v] of (((input) - (1)) / (# costumes))) * (# costumes))) + (1)


to determine which Costume Number to select, which—with 0 as the input—evaluates to:

(((0) - (1)) - (([floor v] of (((0) - (1)) / (# costumes))) * (# costumes))) + (1)
((-1) - (([floor v] of ((-1) / (# costumes))) * (# costumes))) + (1)
((-1) - ((-1) * (# costumes))) + (1)
((-1) + (# costumes)) + (1)
(# costumes)

One can also do:

when green flag clicked
set [number v] to (0)
switch costume to (costume1 v)
next costume
repeat until <(costume [number v]) = (1)>
next costume
change [number v] by (1)

Even though the previous way is easier and faster, this also works.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.