Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Guide to Case Sensing (2.0)
- turkey3
-
1000+ posts
Guide to Case Sensing (2.0)
I'm sure you all are wondering how to case-sense in Scratch 2.0, because it's different than in 1.4. Well, here is a little method I have (all credit to ErnieParke) for you. You only need a sprite with 53 costumes (it's not that bad) and a consistent pattern among the names of the costumes. As you all probably know, costumes cannot be named “b” and “B”: Scratch doesn't allow two costumes of the same character but different cases being named. However, when actually switching to different costumes with blocks, it is case sensitive. First, create the 53 costumes in this order:

-check out the wiki article Case Sensing, now updated fully. Don't say I copied from there since I wrote the article
. To case sense in 1.4, see Case Sensing (1.4).
1. Name the first costume “null”Once the naming is done, make sure the order is correct. Then, insert the following script:
2. Name the second costume “A” (must be capital)
3. Name the third costume “at”
4. continue steps 2 and 3 until the alphabet is complete, meaning the next costume is “B” and then “bt”
define detect case of letter [character]Then, in the sprite with these 53 costumes, any letter can be entered into this block and the output variable will be either “upper” or “lower” depending on the case. Well, that's that
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks like

-check out the wiki article Case Sensing, now updated fully. Don't say I copied from there since I wrote the article

Last edited by turkey3 (Sept. 7, 2013 01:54:44)
- Splodgey
-
100+ posts
Guide to Case Sensing (2.0)
Why do you need the costume mod 2? Surely you can just do this:define detect case of letter [character]
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks like
define detect case of letter [character]
switch costume to [null v]
switch costume to (character)
if <(costume #) = (1)> then
set [case v] to [lower]
else
set [case v] to [upper]
Last edited by Splodgey (Sept. 7, 2013 08:09:51)
- DadOfMrLog
-
1000+ posts
Guide to Case Sensing (2.0)
Ha, nice one Ernie! 
(Can't believe I missed this idea - actually made use of ‘missing’ costume behaviour fairly recently…)
Still would be nice to have it available properly, of course.

(Can't believe I missed this idea - actually made use of ‘missing’ costume behaviour fairly recently…)
Still would be nice to have it available properly, of course.

Last edited by DadOfMrLog (Sept. 7, 2013 08:43:38)
- scubajerry
-
1000+ posts
Guide to Case Sensing (2.0)
Why do you need the costume mod 2? Surely you can just do thisdefine detect case of letter [character]
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks likedefine detect case of letter [character]
switch costume to [null v]
switch costume to (character)
if <(costume #) = (1)> then
set [case v] to [lower]
else
set [case v] to [upper]
The mod is checking for odd or even costume #s. Your script works ok for the letter a, but I don't think it would work well for other letters.
- turkey3
-
1000+ posts
Guide to Case Sensing (2.0)
His is better and only needs 27 costumes. It realized that later when Ernie told me.Why do you need the costume mod 2? Surely you can just do thisdefine detect case of letter [character]
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks likedefine detect case of letter [character]
switch costume to [null v]
switch costume to (character)
if <(costume #) = (1)> then
set [case v] to [lower]
else
set [case v] to [upper]
The mod is checking for odd or even costume #s. Your script works ok for the letter a, but I don't think it would work well for other letters.
- scubajerry
-
1000+ posts
Guide to Case Sensing (2.0)
Oh my mistake. I jumped to the conclusion that lower case letters were in the table. Very clever.His is better and only needs 27 costumes. It realized that later when Ernie told me.Why do you need the costume mod 2? Surely you can just do thisdefine detect case of letter [character]
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks likedefine detect case of letter [character]
switch costume to [null v]
switch costume to (character)
if <(costume #) = (1)> then
set [case v] to [lower]
else
set [case v] to [upper]
The mod is checking for odd or even costume #s. Your script works ok for the letter a, but I don't think it would work well for other letters.
Last edited by scubajerry (Sept. 7, 2013 15:17:33)
- kyle-elyk
-
11 posts
Guide to Case Sensing (2.0)
I need help with my project which needs case sensitivity but I'm not sure this will help. http://scratch.mit.edu/projects/12018189/ Its a binary Converter but the way it works, it will only use capital letters due to scratch not being case sensitive
- ErnieParke
-
1000+ posts
Guide to Case Sensing (2.0)
@DadOfMrLog:
Thanks! I even surprised myself on this one script.
Also, I agree, this would be nice as its own block, but then you lose the fun of discovering how to code it. ;) Still, maybe it could be added…
With considerations,
ErnieParke
Thanks! I even surprised myself on this one script.
Also, I agree, this would be nice as its own block, but then you lose the fun of discovering how to code it. ;) Still, maybe it could be added…
True, it is very clever, but then you can't differentiate between non-letter characters and actually letters. For example, $ would be considered as lower-case, even though it's not a letter. Still, if you know what you're checking is already a letter, then your method would be the more useful of the two.Oh my mistake. I jumped to the conclusion that lower case letters were in the table. Very clever.His is better and only needs 27 costumes. It realized that later when Ernie told me.Why do you need the costume mod 2? Surely you can just do thisdefine detect case of letter [character]
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 #) = (0)> then //if the sprite never changed costumes due to the letter being lowercase
switch costume to (join (character)[t]) //all the lowercase costumes end in a "t" or your lettered choice (refer to the pattern above)
end
if <((costume #) mod (2)) = (0)> then //if the costume is at an interval of "2", meaning if it is switched to a capital letter costume
set [case v] to [upper] //defines that the letter is uppercase
else
set [case v] to [lowercase]
end
detect case of letter [] //what the block looks likedefine detect case of letter [character]
switch costume to [null v]
switch costume to (character)
if <(costume #) = (1)> then
set [case v] to [lower]
else
set [case v] to [upper]
The mod is checking for odd or even costume #s. Your script works ok for the letter a, but I don't think it would work well for other letters.
With considerations,
ErnieParke
- TheLogFather
-
1000+ posts
Guide to Case Sensing (2.0)
At the risk of committing a seriously massive ‘necrobump’… 
String comparison on Scratch is still case-insenstive, so it seemed like this topic basically remains relevant and worth having continued viewing.
In particular, though, I also have a little something to add to this guide… an alternative method that doesn't use costumes (though it does use a single ‘hacked’ block):

https://scratch.mit.edu/projects/64292796/
I think it's a fairly practical & straightforward method (despite the hacked block), so worth knowing about.
Enjoy!

String comparison on Scratch is still case-insenstive, so it seemed like this topic basically remains relevant and worth having continued viewing.
In particular, though, I also have a little something to add to this guide… an alternative method that doesn't use costumes (though it does use a single ‘hacked’ block):

https://scratch.mit.edu/projects/64292796/
I think it's a fairly practical & straightforward method (despite the hacked block), so worth knowing about.
Enjoy!

- deck26
-
1000+ posts
Guide to Case Sensing (2.0)
And for those who don't want to use hacked blocks I've realised there's a way to do upper case detection using two costumes rather than the usual 27.
https://scratch.mit.edu/projects/64732288/
https://scratch.mit.edu/projects/64732288/
- TheLogFather
-
1000+ posts
Guide to Case Sensing (2.0)
Yup, that's really good for reducing the costumes - MrSherlockholmes also mentioned that, and used it along with a And for those who don't want to use hacked blocks I've realised there's a way to do upper case detection using two costumes rather than the usual 27.different case-detection method based on using the case-sensitivity of sounds.
https://scratch.mit.edu/projects/64732288/
There are actually quite a few ways to do case-detection, once you think more about it. For example, using a “go to” block with a variable that contains a sprite's name, but which may have the wrong case. Then you can test if it did go to the sprite - it won't if the case was wrong. (And it makes most sense to do the same kind of thing as you and MrSH above with only a single sprite that has a name made of all the relevant letters).
Still, it'd be much nicer to have some built-in way to do proper case-detection…
Last edited by TheLogFather (May 29, 2015 17:52:18)
- Discussion Forums
- » Help with Scripts
-
» Guide to Case Sensing (2.0)