This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet as we cannot guarantee the safety of other websites.
This article or section documents the current version of Scratch (version 3.0). For this article in Scratch 1.4, see Case Sensing (1.4).
An example of case-insensitivity (the () = () block).

Case sensing is the act of distinguishing lowercase letters from uppercase or capital letters.

Case sensing is a more difficult process than in Scratch 1.4 due to more restrictions on what is and is not case-sensitive. In order to accomplish case sensing in Scratch 3.0 and Scratch 2.0, any of a small variety of methods must be employed, usually exploiting the case-sensitivity of the Switch Costume to () block.

Note Note: This article only uses the standard English 26 letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ). More characters may need to be added in some parts of the script to differentiate more letters.

53 Costume Method

Costume names case-sensitive, for example, a sprite can have a costume named "A" and a costume named "a". The switch costume to ( v) block can be used to switch to a costume of a given name, and the (costume [number v]) block can be used to distinguish them by costume number.

This method requires creating pairs of costumes for every letter to be detected — one uppercase and one lowercase. An additional costume named something else such as "null" is also needed as a default for when a letter isn't found. For this example, the costumes should be in the order: null, A, a, B, b, C, c, ...

is uppercase [a]
say (return) // example usage of the result found by the custom block script

define is uppercase (character)
switch costume to (null v)
switch costume to (character) // attempt to switch to the costume of a given character
if <(costume [name v]) = [null]> then
  set [return v] to [] // the character wasn't found in the costume names, return nothing
else
  if <((costume [number v]) mod (2)) = [0]> then
    set [return v] to [true] // costume numbers 2, 4, 6, ... are uppercase
  else
    set [return v] to [false] // costume numbers 3, 5, 7, ... are lowercase
  end
end

This method is the fastest as it doesn't require any loops.

Two Costume Method

Instead of costumes for each letter as seen in the 53 Costume Method, the letters can be merged into two costumes. One must be called ABCDEFGHIJKLMNOPQRSTUVWXYZ, and the other can be named anything else such as "null". This method loops over every supported letter to build a new costume name, substituting one letter with the input.

define is uppercase (character)
set [supported characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ] // uppercase
set [i v] to [1] // counter
set [str v] to [] // join letters to form a new costume name
repeat (length of (supported characters))
    if <(letter (i) of (supported characters)) = (character)> then
        set [str v] to (join (str) (character)) // substitute with input character
    else
        set [str v] to (join (str) (letter (i) of (supported characters)))
    end
    change [i v] by (1) // increment counter
end
switch costume to (null v)
switch costume to (str) // attempt to switch to the costume of the above built string
if <(costume [name v]) = [null]> then
    set [return v] to [false] // failed to switch, return false
else
    set [return v] to [true] // the input character is uppercase, return true
end

Distance Method

Similar to the "Two Costume Method", instead of costumes, this script uses the distance to ( v) block, since it is case-sensitive. The sprite this script is on must be named ABCDEFGHIJKLMNOPQRSTUVWXYZ.

define is uppercase (character)
set [supported characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ] // uppercase
set [i v] to [1] // counter
set [str v] to [] // join letters to form a new costume name
repeat (length of (supported characters))
    if <(letter (i) of (supported characters)) = (character)> then
        set [str v] to (join (str) (character)) // substitute with input character
    else
        set [str v] to (join (str) (letter (i) of (supported characters)))
    end
    change [i v] by (1) // increment counter
end
if <(distance to (string)) = [0]> then
    set [return v] to [true] // uppercase
else
    set [return v] to [false] // lowercase

It can be done with two sprites, one named ABCDEFGHIJKLMNOPQRSTUVWXYZ, another with the above code, as long as they have the same coordinates.

() of () Method

Sprite names are case sensitive. This script uses the [ v] of ( v) block, as it is case sensitive. The sprite must be named ABCDEFGHIJKLMNOPQRSTUVWXYZ.

define is uppercase [character]
set [supported characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ] // uppercase
set [i v] to [1] // counter
set [str v] to [] // join letters to form a new costume name
repeat (length of (supported characters))
    if <(letter (i) of (supported characters)) = (character)> then
        set [str v] to (join (str) (character)) // substitute with input character
    else
        set [str v] to (join (str) (letter (i) of (supported characters)))
    end
    change [i v] by (1) // increment counter
end
if <([costume # v] of (str)) = [0]> then // this checks if the variable of the sprite equals zero, that means the sprite does not exist
    set [return v] to [false] // lowercase
else
    set [return v] to [true] // uppercase
end

52 Variables Method

This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.

Variables names can also be used to check the case of a character. For example, one could have a variable named "A" and a variable named "a". This method is faster than the 53 costumes method and 2 costumes method.[citation needed]


Note Warning: This method uses a few edited blocks that can be obtained by editing the JSON of a project.

This script will only work in Scratch 2.0.

define Create Vars
set [Characters v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]
set [p1 v] to [1]
repeat (26)
  set (letter (p1) of (Characters)) to [1]
  change [p1 v] by (1)
end
repeat (26)
  set (letter (p1) of (Characters)) to [0]//these edited blocks were used to speed up the process of creating 52 variables, they are not necessary but saves the trouble of having to manually create and set 52 separate variables
  change [p1 v] by (1)
end
define isUppercase (character)
if <((character) of (Sprite1 v)) = [1]> then//This edited block checks the value of a variable in a specific sprite, replace Sprite1 with whatever sprite one ran the Create Vars custom block on
  set [is uppercase v] to [yes]
else
  set [is uppercase v] to [no]

Four Variables Method

This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective.

Variables names are case-sensitive. This is faster than the 53 costumes method and 2 costumes method and uses fewer variables then the 52 Variables method, therefore, people might use this method.

Note Warning: This method uses a few edited blocks that can be obtained by editing the JSON of a project—don't use this method until feeling ready to edit JSON files or use edited blocks appropriately. This script will only work in Scratch 2.0.
define is uppercase (character)
// Run without screen refresh is recommended
set [ABCDEFGHIJKLMNOPQRSTUVWXYZ v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ] // This is needed
set [str v] to []
set [i v] to [0]
repeat (26)
change [i v] by (1)
if <(letter (i) of [ABCDEFGHIJKLMNOPQRSTUVWXYZ]) = (character)> then
set [str v] to ( join (str) (character) )
else
set [str v] to ( join (str) (letter (i) of (ABCDEFGHIJKLMNOPQRSTUVWXYZ) )
end
end
if <((str) of (x v)) = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]> then // This is edited to check does the variable exists if not it will return "0". Replace x with the sprite one ran this block on (unless the variable "ABCDEFGHIJKLMNOPQRSTUVWXYZ" is for all sprites, if that is the case replace x with Stage)
set [is uppercase v] to [true]
else
set [is uppercase v] to [false]
end

See Also