Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Detect user input
- verjin
-
6 posts
Detect user input
Hello I am having 2 issues with my current project. I am expecting when I input numbers, it will say “Please don't type in numbers”.Example:1234. If I input letters with numbers it will say“Invalid name”.Example:r2d2. The sprite will keep asking until the user input only letters. What should I do now?
I used the code from a scratcher, if I type in only numbers then it says “Please don't type in numbers”.If I input letters only or letters with numbers, It will say what you have just type in.
Here is the link:
https://scratch.mit.edu/projects/323577775
Those are my two final issues. Thank you for spending your time.
I used the code from a scratcher, if I type in only numbers then it says “Please don't type in numbers”.If I input letters only or letters with numbers, It will say what you have just type in.
Here is the link:
https://scratch.mit.edu/projects/323577775
Those are my two final issues. Thank you for spending your time.
- deck26
-
1000+ posts
Detect user input
Do you mean you want it to reject names which include numbers because r2d2 works fine for me.
If you want to eliminate all names that only include letters you'd need to check each letter separately to make sure it is ok.
Create a list containing the letters a-z as individual items. Then loop through the input one character at a time and check that the list contains that character. If it doesn't the name fails.
If you want to eliminate all names that only include letters you'd need to check each letter separately to make sure it is ok.
Create a list containing the letters a-z as individual items. Then loop through the input one character at a time and check that the list contains that character. If it doesn't the name fails.
- BT_Test
-
5 posts
Detect user input
Hi, Try this code that i wrote below
Last edited by BT_Test (Aug. 8, 2019 18:03:52)
- BT_Test
-
5 posts
Detect user input
Opps sorry i mistyped the codes above Hi, Try this code that i wrote below
- jacobsmash1
-
100+ posts
Detect user input
Very long or loop, idk if there is a better way to optimize it.
- Devyev
-
5 posts
Detect user input
first add numbers to a list Hello I am having 2 issues with my current project. I am expecting when I input numbers, it will say “Please don't type in numbers”.Example:1234. If I input letters with numbers it will say“Invalid name”.Example:r2d2. The sprite will keep asking until the user input only letters. What should I do now?
I used the code from a scratcher, if I type in only numbers then it says “Please don't type in numbers”.If I input letters only or letters with numbers, It will say what you have just type in.
Here is the link:
https://scratch.mit.edu/projects/323577775
Those are my two final issues. Thank you for spending your time.
then add another list
add this code:
sorry I cant finish
- verjin
-
6 posts
Detect user input
Opps sorry i mistyped the codes above Hi, Try this code that i wrote below
- verjin
-
6 posts
Detect user input
Sorry that I have messed up the reply but what I am trying to say is that Devyev and BT_Test code connot dectect when I input f4.If I input a number and a letter the computer still consider it as letter. Does anyone know how to fix it. It is very close
- deck26
-
1000+ posts
Detect user input
I've already given you my answer - did you try it as it shouldn't be difficult and should be more compact than the code you showed? Sorry that I have messed up the reply but what I am trying to say is that Devyev and BT_Test code connot dectect when I input f4.If I input a number and a letter the computer still consider it as letter. Does anyone know how to fix it. It is very close
https://scratch.mit.edu/projects/323686119/ is a quick demo. It only eliminates names containing digits. If you want to reject any non-letter characters you'd be better reversing the logic and rejecting any name that contains a character that is not in the list.
Last edited by deck26 (Aug. 9, 2019 09:03:38)
- Huskeygammings
-
1 post
Detect user input
so how we can detect an input from an answer is using this code, here is an example.
- Discussion Forums
- » Help with Scripts
-
» Detect user input