Search code examples
mit-scratch

How to get the case of a letter in scratch?


I'm trying to turn a string into a number, but apparently Scratch ignores the case when returning the list item of a string. So, how would I make it so that scratch pays attention to the case when giving me the letter's corresponding number?

Edited: string returning with wrong case


Solution

  • The "set costume to (name)" block is case sensitive, so it should solve your problem.

    It looks like you are attempting to convert a ASCII character into a number. You can implement this with the following steps:

    • Create around 90 costumes with the different ASCII characters you want to use.

    • Then use "set costume to (queried character)" block found in the looks tab.

    • The "(costume number)" variable (found in the looks tab) will be your output number.

    If you want to convert a number back into ASCII you can use the following steps:

    • Make sure you have the special costumes from step 1
    • Use "set costume number to (number)".
    • The "(costume name)" variable (found in the looks tab) will be the original character.

    The only obvious downside to using this method is that encoding or decoding will change the current costume of the sprite, so I usually make a separate sprite if I want to use costumes.