Making a Typewriter/ Keyboard


Okay, so I’m making a typewriter on Hopscotch. And I’m making a text that says “Change Case”. For example, if the letters are A, B, and C, I want them to be changed to a, b, and c. But how do you change them back when you press the button for the second time? Thanks. :grin:


You could have a variable of “Case” and set it so when Case = 1 Set A to a And Case = 2 set a to A. Not quite sure how that would work, but to sum it up, you could assign a variable number to upper/lowercase so when Case = certain number, it will change.


Thank you for the reply, though I’m still a bit confused. Here’s the link:


Make a value, I’ll call it “case,” and use it to determine the case of the letter typed; let 0 represent lowercase and 1 represent uppercase. What we want is for it to alternate between 0 and 1 (or any two numbers you pick, but I like 0 and 1 for simplicity and because the default is 0) when you tap the “Change Case” button. In order to do that, the object needs to know whether the case is 1 or 0 and then change it to what it is not. You can do this with control blocks, specifically, the “check if else” block.

When Change Case is tapped:
Check once if case = 0
Set case to 1
Set case to 0

If you need further explanation or an example, please don’t hesitate to tag me or reply back.

This is going to sound weird, but it warms my heart that a new user is on the forum and genuinely talking about code


I think that you should keep it down to just one variable. I’ve modified your code so that it works with the current variables though. Here’s the fixed version:


@William04GamerA When I tapped change case,only the letter A changed case.


The code from the letter A needs to be copied to all other letters. I thought I did that though. Good catch, I’m happy that I could clarify this.


How about changing the case of the clones? Is there some way I can do that? By the way, thank you for all your amazing comments! :heart:


Changing the case of the clones?


Be careful with the use of Repeat Forever blocks. This is the most overused & misused block in Hopscotch.

Here’s what I would suggest:

Delete the Repeat Forever & the 1st two Check Ifs. Just keep the last Check If Else. You don’t need the Repeat Forever because it’s already in a When Tapped rule, so the code runs according to the event (When “Change Case” is Tapped) instead of looping forever.

Also copy that same Check If Else to the When Cloned rule.

Do those two things for all letters. (Or just test first with A)

Last, add these two rules to the “Change Case” object. We only need :iphone:Upper Case since according to the Check If Elses above, a value of 1 means upper case and any other value means lower case.

The last block that’s partially cut off is:
Set :iphone:upper case = :iphone:upper case * -1

That just toggles the variable between 1 and -1 without needing a Check If Else (remember a value of anything other than 1 is lower case, so -1 works just fine for the lower case state)
1 * -1 = -1
-1 * -1 = 1


Your solution is the one that @RobertTheFlash should use. Thank you for sharing it!

And that code also changes the case of the clones, right?


Yes, the clones will match the state of keyboard (upper or lower case) when you type.


Does it make sense that this is supposed to happen? When I press change case, it changes the case of all of the clones. Is there any way I can fix this? (This was actually the question I had earlier, if you were all confused.)


Ah, sorry. I missed that.

For each of the letters, under the When “Change Case” is Tapped rule, move the Check If Else under this:

Check Once If (self) Clone Index = 1

So it would look like this:

That way only the original clone (the one for the keyboard) will change.


Also you may have noticed that the first time you tap Change Case, the keyboard doesn’t change. But after that, it’s fine.

This behavior is because of the order in which the Objects were created. The letters are first, followed by the ‘Change Case’ Text. So the letters’ Check If Else :iphone:upper case = 1 is evaluated before the variable is changed.

Move the ’Change Case’ Text up before all the letters, and it’ll work the first time.