From Test-Scratch-Wiki

Translate: - English - 中文 
This article or section documents an outdated version of Scratch (version 2.0). For this article in Scratch 1.4, see Zho:大小写字母区辨 (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 角色 consisting of 53 造型 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 造型换成 () series are case-sensitive. The 程式ing method below shows how to set a 变量 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 函式积木 to detect if a letter entered into the string input is capitalized or not.

定義 detect case of letter (character)
如果 <<(字串長度\( (character) \)) = (1)> 不成立> 那麼 
  變數 [case v] 設為 [error!] // indicates that more than one character was entered, or there was no length
  停止 [這個程式 v]
end
造型換成 [null v] // it should be your very first costume
造型換成 (character) // if the character is lowercase, it will stay on "null"
如果 <(造型编号) = (1)> 那麼 
  造型換成 (字串組合 (character) 和 [t]) // all lowercase costumes end in "t" or your lettered choice (refer to pattern above)
end // if the sprite never changed costumes due to the letter being lowercase
如果 <(造型编号) = (1)> 那麼 
  變數 [case v] 設為 [other] // indicates that a non-alphabetic character was used
  停止 [這個程式 v]
end // if the sprite still has not changed costume
如果 <((造型编号) mod (2)) = (0)> 那麼 
  變數 [case v] 設為 [upper] // defines that the letter is uppercase

  變數 [case v] 設為 [lowercase]
end // if the costume is at an interval of "2", meaning it is a capital letter costume
 

Two Costume Method

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

定義 detect case of letter (character)
如果 <<(字串長度\( (character) \)) = (1)> 不成立> 那麼 
  變數 [case v] 設為 [error!] // indicates that more than one character was entered, or there was no length
  停止 [這個程式 v]
end
造型換成 [null v] // it should be your very first costume
造型換成 (character) // if the character is lowercase, it will stay on "null"
如果 <(造型编号) = (1)> 那麼 
  造型換成 (字串組合 (character) 和 [t]) // all lowercase costumes end in "t" or your lettered choice (refer to pattern above)
end // if the sprite never changed costumes due to the letter being lowercase
如果 <(造型编号) = (1)> 那麼 
  變數 [case v] 設為 [other] // indicates that a non-alphabetic character was used
  停止 [這個程式 v]
end // if the sprite still has not changed costume
如果 <((造型编号) mod (2)) = (0)> 那麼 
  變數 [case v] 設為 [upper] // defines that the letter is uppercase

  變數 [case v] 設為 [lowercase]
end // if the costume is at an interval of "2", meaning it is a capital letter costume

54 Variables Method

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, which is the only reason anyone would ever use this method.

Warning Warning: This method uses a few edited blocks that can be obtained by 编辑 JSON 档 of a project - use an above method if you don't feel like you are ready to edit JSON files or use edited blocks appropriately.

定義 Create Vars
變數 [Characters v] 設為 [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]
變數 [p1 v] 設為 [1]
重複 (26) 次 
  變數 (字串中第 (p1) 字\( (Characters) \)) 設為 [1]
  變數 [p1 v] 改變 (1)
end
重複 (26) 次 
  變數 (字串中第 (p1) 字\( (Characters) \)) 設為 [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 
  變數 [p1 v] 改變 (1)
end

定義 Check if (Letter) is Uppercase
如果 <((Letter) \( [角色1 v] \)) = [1]> 那麼 
  變數 [isUppercase v] 設為 [yes]

  變數 [isUppercase v] 設為 [no]
end // This edited block checks the value of a variable in a specific sprite, replace Sprite1 with whatever sprite you ran the Create Vars custom block on