This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.
  • Index
  •  » Advanced Topics
  •  » a solution to the case insensitive = block (could do with improvement)

#1 2012-03-02 14:30:00

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

a solution to the case insensitive = block (could do with improvement)

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))
end
This should be fairly self-explanatory, but I was very excited that this worked!

It does, however, mean adding 50 costumes to a Scratch sprite, which isn't very space-saving or efficient.

Does anyone else have a workaround?

smile

Last edited by sparks (2012-03-02 14:31:20)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2012-03-02 15:55:38

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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)

:'(


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#3 2012-03-02 16:04:49

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

What about using numbers? I saw your other thread about letter to number--you could make that upper and lower-case...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#4 2012-03-02 16:20:50

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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

Code:

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


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2012-03-02 16:24:20

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

I missed that...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#6 2012-03-02 16:36:00

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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  smile


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#7 2012-03-02 17:42:32

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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  smile

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 =:

Code:

^t1 = t2

case insensitive =:

Code:

^ 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...


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2012-03-02 18:01:16

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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.  sad
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

 

#9 2012-03-03 00:52:53

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

It's sort of annoying, but there are workarounds for it.^^^


http://trinary.tk/images/signature_.php

Offline

 

#10 2012-03-03 14:23:53

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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.  sad
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

 

#11 2012-03-03 14:33:30

muppetds
Scratcher
Registered: 2011-02-11
Posts: 1000+

Re: a solution to the case insensitive = block (could do with improvement)

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.  sad
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?


SCRATCH'S PARTLY INSANE RESIDENT 
http://internetometer.com/imagesmall/31691.pnghttp://bluetetrarpg.x10.mx/usercard/?name=muppetds

Offline

 
  • Index
  •  » Advanced Topics
  •  » a solution to the case insensitive = block (could do with improvement)

Board footer