From Test-Scratch-Wiki

Revision as of 19:09, 12 June 2016 by InterwikiBot (talk | contribs) (Uploading Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

This article or section documents an outdated version of Scratch (version 2.0). For this article in Scratch 1.4, see Eng:Case Sensing (1.4).

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 2.0, a sprite consisting of 53 costumes must be used.

53 Costume Method

The naming of costumes itself is not case-sensitive — one cannot name two costumes the same letter but in a different case (for example, an individual sprite cannot have a costume called "a" and one called "A"). However, the blocks in the Switch Costume to () series are case-sensitive. The scripting method below shows how to set a variable to "upper" or "lower" in accordance with the case of a specified letter. First, the following procedure on the naming of costumes must be done in order for this to work:

  • The very first costume must have the name "null" or any other non-interfering name
  • Next, beginning with the very first letter of the alphabet, name the next costume "A" (capitalized)
  • The following costume must be named "at" or "a[any other letter]", except the second letter must be consistent throughout the paternal naming
  • Repeat the second and third steps for the rest of the alphabet. This means the next three costumes are "B", "bt", and "C". It is finished once the entire alphabet is complete.

After completing the naming of all 53 costumes, assure that they are in order, and proceed to the scripting. The following script uses a custom block to detect if a letter entered into the string input is capitalized or not.

define detect case of letter [character]
if <(length of (character)) > [1]> then
    set [case v] to [error!] //indicates that more than one character was entered
    stop [this script v]
switch costume to [null v] //it should be your very first costume
switch costume to (character) //if the character is lowercase, it will stay on "null"
if <(costume #) = (1)> then //if the sprite never changed costumes due to the letter being lowercase
    switch costume to (join (character) [t]) //all lowercase costumes end in "t" or your lettered choice (refer to pattern above)
if <(costume #) = (1)> then //if the sprite still has not changed costume
    set [case v] to [other] //indicates that a non-alphabetic character was used
    stop [this script v]
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning it is a capital letter costume
    set [case v] to [upper] //defines that the letter is uppercase
    set [case v] to [lowercase]

Two Costume Method

Costumes are case-sensitive, which may be exploited for case sensing. Two costumes are necessary. One must be called ABCDEFGHIJKLMNOPQRSTUVWXYZ.

define isUppercase (char)
set [supportedChars v] to [ABCDEFGHIJKLMNOPQRSTUVWXYZ]
set [i v] to [1]
set [str v] to []
repeat (length of (supportedChars))
    if <(letter (i) of (supportedChars)) = (char)>
        set [str v] to (join(str)(char))
        set [str v] to (join(str)(letter (i) of (supportedChars))
    change [i v] by [1]
switch costume to [null v] //This is the second costume
switch costume to (str)
if <(costume #) = [1] //The first costume is ABCDEFGHIJKLMNOPQRSTUVWXYZ
    set [isUpperCase v] to [true]
    set [isUpperCase v] to [false]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.