Discuss Scratch

sabrahams-tcssh
Scratcher
13 posts

Changing Lowercase Letters Into Uppercase

Hi! So I have a project where I want to switch a costume to an answer, but answering in lowercase letters causes the costume (whose first letter is in uppercase) not to work. How can I switch the first letter from lowercase to uppercase?

I tried setting a variable called letter to the first letter of the answer and joining it to the answer without its first letter, but the “answer - letter 1 of answer” part didn't work. Can anyone help?

Thanks!
CringeyCracker
Scratcher
34 posts

Changing Lowercase Letters Into Uppercase

sabrahams-tcssh wrote:

Hi! So I have a project where I want to switch a costume to an answer, but answering in lowercase letters causes the costume (whose first letter is in uppercase) not to work. How can I switch the first letter from lowercase to uppercase?

I tried setting a variable called letter to the first letter of the answer and joining it to the answer without its first letter, but the “answer - letter 1 of answer” part didn't work. Can anyone help?

Thanks!
Instead of changing the costume to the answer, I'd use an if-else block.

Don't do this
when green flag clicked
ask [Yes or no?] and wait
switch costume to (answer)

Do this
when green flag clicked
ask [Yes or no?] and wait
if <(answer) = [yes]> then
switch costume to [Yes v]
else
if <(answer) = [no]> then
switch costume to [No v]
end
end

when I receive [Follower]
say [Yay!]
broadcast [Celebrate!]
Nezon
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

Jareddddddd wrote:

there currently isnt any way to detect between upper and lowercase.
Costumes are case sensitive

This is my signature (it goes automatically under every post I make)! Here is a bit of advice on foruming, by the way. Don't do SAND. SAND means four words.
SAND means Spam, Advertising, Necroposting, and Derailing.
Spam is when a irrelevant message is sent to many places. Wiki Article: Spam
Advertising is when you promote your studios and projects. Wiki Article: Advertising
Necroposting is when you post on a old topic. It distracts other helpers! Wiki Article: Necroposting
Derailing is when you post something that is irrelevant to the topic, like minimodding. It is called thread hijacking. Wiki Article: Derailing(Derailing idea comes from this guy),
in the process of leaving scratch.
bob has been hidden again :(

deck26
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

@CringeyCracker's solution should work fine but if you have multiple costume names to cope with it might be easier to amend the input.

Create a list containing capital letters, one per item. Use the ‘item # of item in list’ block to get the item number of the first letter in the list - Scratch won't care if it is upper or lower case at that stage. So you can now set a variable to the capital version of that letter. Then you can loop through the remaining letters of the input and append each in turn to the variable.

The lack of decent text handling is my major bugbear with Scratch.
sabrahams-tcssh
Scratcher
13 posts

Changing Lowercase Letters Into Uppercase

Ok- Thank you all so much!
RT_Borg
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

Hi sabrahams-tcssh (and deck26),

Here's a less tedious workaround.

Demo: Case Sensitive Costumes
https://scratch.mit.edu/projects/696277357

I build a list of all costumes (with a reusable block), look for the input in the list, and then on a match use the list item to switch costumes. (The demo uses single character costume names, but the reusable “build costume-names list” block will work with any costume names.

I hope this helps. I'm happy to answer any questions.

– RT_Borg
deck26
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

RT_Borg wrote:

Hi sabrahams-tcssh (and deck26),

Here's a less tedious workaround.

Demo: Case Sensitive Costumes
https://scratch.mit.edu/projects/696277357

I build a list of all costumes (with a reusable block), look for the input in the list, and then on a match use the list item to switch costumes. (The demo uses single character costume names, but the reusable “build costume-names list” block will work with any costume names.

I hope this helps. I'm happy to answer any questions.

– RT_Borg
Well it's the same as my solution except the costume names are single characters so there is nothing to add once you've handled the first character. perfectly valid as a solution if the OP is happy with that and does reduce the work.
RT_Borg
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

deck26 wrote:

Well it's the same as my solution except the costume names are single characters so there is nothing to add once you've handled the first character. perfectly valid as a solution if the OP is happy with that and does reduce the work.

Automating the costume list also handles multi-character costume names (like yes/no, on/off, red/green/blue, human/elf/ogre/orc) with 0 changes to the code (no manually building a map of all possible letters-and updating it when the choices change, no loop appending characters to build an uppercase version of input, and I'm not sure how your version would deal with costume names that aren't entirely upper case).

– RT_Borg
deck26
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

RT_Borg wrote:

deck26 wrote:

Well it's the same as my solution except the costume names are single characters so there is nothing to add once you've handled the first character. perfectly valid as a solution if the OP is happy with that and does reduce the work.

Automating the costume list also handles multi-character costume names (like yes/no, on/off, red/green/blue, human/elf/ogre/orc) with 0 changes to the code (no manually building a map of all possible letters-and updating it when the choices change, no loop appending characters to build an uppercase version of input, and I'm not sure how your version would deal with costume names that aren't entirely upper case).

– RT_Borg
My apologies, I didn't fully explore what you'd done. A good solution which, as you say, doesn't only work with single character names.
RT_Borg
Scratcher
1000+ posts

Changing Lowercase Letters Into Uppercase

Cheers deck26, always nice crossing paths with you in the forum. (And I've found myself pointing people to projects in your Forum Links and Demos studios a few times already.)

– RT_Borg

Powered by DjangoBB