I am trying to build an ascii-char to binary converter.
A sprite asks the user for a character to convert (currently, I only want it to convert 1 character) and I want it to accept 0-9, a-z and A-Z.
First, depending on the answer, the decimal number for that character is stored in a variable which then is later passed to the scripts that display the binary equivalent of said character/decimal. The display binary part is working without flaw, but I ran into a serious problem when I parse the answer to get the decimal number for that character:
Scratch does not care if an answer is lower or uppercase.
It looks like this:
if answer = 8 then asciidecimalvariable = 56
if answer = 9 then asciidecimalvariable = 57
if answer = A then asciidecimalvariable = 65
if answer = a then asciidecimalvariable = 97
But no matter if I answer A or a, the variable will always get filled with 97 (scratch does not check if it's uppercase or not). Is there a way I can make this work?
Offline
You can ask capital of lowercase?
if capital set letter to A
else set letter to a
Offline
@firedrake You mean this?
if <(capital) = [1]> set [letter v] to [A] else set [letter v] to [a]I don't know if that would work, but... Whatever.
Offline
I'd rather avoid to have to specificially ask the user if his answer is upper or lowercase. But I might have found something that may work in the wiki, I'm not sure though if I can implement it properly.
Offline
Ok, i got around the problem using a list for lower case letters, apparently when comparing an answer to a list, lower and uppercase DOES get respected.
So now i first add all lower case letters to a list like
add a to <lowercaselist>
add b to <lowercaselist>
etc
then, as before I have
if answer = A then asciidecimalvariable = 65
if answer = B then asciidecimalvariable = 66
...
if answer = Z then asciidecimalvariable = 90
and now I check if the answer is part of the lowercaselist which would mean that the answer actually was in lowercase.
if lowercaselist contains answer then asciidecimalvariable = asciidecimalvariable + 32
I hope this helps anyone who might run into a similar problem.
Offline
http://wiki.scratch.mit.edu/wiki/Case_Sensing
This should help.
Offline
Yeah I basically implemented this. It is somewhat working now (I finnished and uploaded the project, you can check it out here: http://scratch.mit.edu/projects/molkemon/3138922
However, even with the workaround, it does NOT work with the flash player version. It does work correctly though with the java player or if you download the project. I have reported this as a bug.
Offline