Pages: 1
Hi guys,
I'm currently working on a new version of my popular Block Creator project. This one uses pixel rendering for a more accurate, glitch free result. However, because it is drawing, it's no longer using costumes to stamp letters.
In fact, as it's now reading from a list I have once again hit the famous case-insensitive = block problem. Then I realised I had a solution!
I was about to lie there, screaming and ripping my hair out that I couldn't get case sensitivity this way, when I realised I could use a the costumes technique from the last block creator to my advantage because costume names are case-sensitive!
This means that I can judge the case of any letter by creating a sprite with 52 costumes, named a-z, A-Z. Using this script a character case can be returned:
when gf clicked ask [type a single letter in upper or lower case] and wait switch to costume (answer) if <(costume #) > [26]> say (join [that's an upper-case] (answer)) else say (join [that's an lower-case] (answer)) endThis should be fairly self-explanatory, but I was very excited that this worked!
Last edited by sparks (2012-03-02 14:31:20)
Offline
Alternately, (I'm crying about this) it turns out that whilst the
<[a]=[A]>block isn't case-sensitive, the
<[list v] contains [A]?>block IS. So all you need is a list with the values A-Z. If the character is contained, you know it's capital, otherwise it's lowercase (or a non-alphabetical character)
Offline
What about using numbers? I saw your other thread about letter to number--you could make that upper and lower-case...
Offline
bobbybee wrote:
What about using numbers? I saw your other thread about letter to number--you could make that upper and lower-case...
Well the other thread is sort of what brought me to this. It was looking through a list, item by item until it found the item that matched the search character. By storing them alphabetically it lets you know which number each character is. However, in the list
a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
it would always stop in the first 26 digits, because the F returns true AS WELL AS f. So using numbers won't work, as storing them in a list with their numbers causes the reference problem in the first place.
But it's okay, cos we have TWO solutions now
Offline
I missed that...
Offline
The costume approach is very clever! But I think I prefer the list method as it's less space intensive and easier to implement. It is pretty whacky that the equals operator isn't case sensitive but the contains operator is. Just one of those little inconsistencies that makes Scratch programming such an adventure
Offline
Paddle2See wrote:
The costume approach is very clever! But I think I prefer the list method as it's less space intensive and easier to implement. It is pretty whacky that the equals operator isn't case sensitive but the contains operator is. Just one of those little inconsistencies that makes Scratch programming such an adventure
![]()
Thanks, Paddle, I was so pleased with myself when I found this out! And then when I was about to test it online against the contains block, I suddenly realise the contains block WAS! ¬_¬ Bummer.
I don't know if you do much smalltalk, but what's really interesting is that it's easier to make a case-sensitive = block than an insensitive one!
case sensitive =:
^t1 = t2
case insensitive =:
^ t1 asLowercase = t2 asLowercase
Now I'm no smalltalk expert, there may be other, more complex ways to do it that error-catch and such, but this suggests to me that the Scratch team purposefully made it case-insensitive. I can sort of understand why this might have been seen as a good idea because to people new to programming, it may cause a lot of confusion if two seemingly identical pieces of text don't match. Of course, string support wasn't actually introduced until Scratch 1.4. I remember those dark days...
Offline
sparks wrote:
I was about to lie there, screaming and ripping my hair out that I couldn't get case sensitivity this way, when I realised I could use a the costumes technique from the last block creator to my advantage because costume names are case-sensitive!
*crys*
If that was literal, I feel sorry for you. I'm literally almost crying right now.
If that wasn't, it's a problem with me-- I think literally.
I'm at least 200% glad you found a solution.
Infact, at the time of editing, I'm still almost crying.
Last edited by rdococ (2012-03-03 05:11:15)
Offline
rdococ wrote:
sparks wrote:
I was about to lie there, screaming and ripping my hair out that I couldn't get case sensitivity this way, when I realised I could use a the costumes technique from the last block creator to my advantage because costume names are case-sensitive!
*crys*
If that was literal, I feel sorry for you. I'm literally almost crying right now.![]()
If that wasn't, it's a problem with me-- I think literally.
I'm at least 200% glad you found a solution.
Infact, at the time of editing, I'm still almost crying.
I'm a big fan of ripping hair out. My parents say I need therapy. ._.
Ontopic: The wiki has a whole page about case sensing and changing: Case Sensing.
Offline
rdococ wrote:
sparks wrote:
I was about to lie there, screaming and ripping my hair out that I couldn't get case sensitivity this way, when I realised I could use a the costumes technique from the last block creator to my advantage because costume names are case-sensitive!
*crys*
If that was literal, I feel sorry for you. I'm literally almost crying right now.![]()
If that wasn't, it's a problem with me-- I think literally.
I'm at least 200% glad you found a solution.
Infact, at the time of editing, I'm still almost crying.
11 hours of crying?
Offline
Pages: 1