Discuss Scratch

gusdn2
Scratcher
66 posts

How to I sort the captial letter and small letter?

How to I sort the captial letter and small letter?
<[A] = [a]>
It says true…
How to I do it???
SuperMarioFan4
Scratcher
100+ posts

How to I sort the captial letter and small letter?

It's not case-sensitive, so you can't.

Wait, are you making a suggestion or are you asking?

Last edited by SuperMarioFan4 (Nov. 7, 2016 15:39:20)


I will answer the basic questions on the forums. Advanced stuff? Ask someone else.

My name is Eggs Benedict. I'm an angsty teen who likes to listen to casual bongos, and likes to eat exotic butters.

psychrometer
jokebookservice1
Scratcher
1000+ posts

How to I sort the captial letter and small letter?

gusdn2 wrote:

How to I sort the captial letter and small letter?
<[A] = [a]>
It says true…
How to I do it???
That is an excellent question!

Scratch's “=” operator is not case sensitive, which means it doesn't care whether it uses big letters or small letters. However, costume names, sound names, variable names, and so on, do care about case, which means
switch costume to [Hi v]
is different to
switch costume to [hi v]
While we can't directly type text into the costume blocks, we can drag round blocks (called reporters) into the dropdowns. Scratch doesn't let blocks into every dropdown, but it does for the costume blocks.

You'll need to create a costume for every letter for the alphabet in lowercase, and another costume– call it something like “null”. In order to detect whether a letter is lowercase, we will

  • Switch to costume “null”
  • Switch to costume with the name of the letter (non-lowercase letters will keep the costume at “null”)
  • Remember the costume number in a variable
  • Switch to costume “null”
  • Switch to costume with the name of the other letter (again, it will stay on the current costume, null, if it fails to find the costume)
  • Check the current costume and compare it the stored costume number
  • Check that the letters are the same when using Scratch's method
Here is a table to show what the costumes numbers will be with the different combinations of “a” and “A”. (let's say the costumes are “null”, and “a”). If the two costume numbers will be the same, let's put a T, and if they will be different, let's put an F.
+-----+-----+-----+
| | a | A |
+-----+-----+-----+
| a | T | F | For the first one, it is both costume "a"; the second, one "NULL" and the other "a"
+-----+-----+-----+
| A | F | T | For the first one, one "NULL" and one "a"; the second, both "NULL"
+-----+-----+-----+

However, this forgets about checking using the Scratch test on top of that– if you omit the Scratch test step then you will find all capital letters are the “same” in the eyes of this system.

As you can see, this system will work. Finally, let's talk about variables before finally writing some code. To make a variable, we can go to the “Data” category, and then click “Make a variable”. A variable is like a box in memory, with a name (call it “Old Costume”) and a value (the stuff inside the box), which we can change using blocks. Once you've made a variable, you'll see new blocks appear. One of them is
set [Old Costume v] to []
which sets the value of the variable (the stuff inside the box) to the second slot. Another block is
(Old Costume)
which will report the value of the variable.

Now, make one more variable, and call it “counter”.

Ok, now to write some code. We are going to test if a letter entered by the user is the same as “H”. Make sure you have made 26 costumes named “a” to “z”
when green flag clicked
ask [enter ONE letter] and wait
switch costume to [NULL v]
switch costume to (answer)
set [Old Costume v] to (costume #)
switch costume to [NULL v]
switch costume to (join [] [H]) //Costume "H" does not exist, this is on purpose
if <<(Old Costume) = (costume #)> and <(answer) = [H]>> then
say [The letter was H]
else
say [The letter wasn't H]
end

So the costume detects whether the letter is a lowercase letter or not. Once you know both letters are lowercase/uppercase, you also need to check they are the same, hence the old “=” method.

Now I hear you ask, “Why did we create the ‘counter’ variable?”. This is because we need to loop through each letter if you have many letters. You might want to use this variable to keep track of which letter you are currently testing. I'm going to leave this part to you, but if you need help, just ask.

Also, this might be the wrong section to post for help. Don't worry though, I'll ask a moderator to move it for you
gusdn2
Scratcher
66 posts

How to I sort the captial letter and small letter?

thank you very much!

Powered by DjangoBB