Discuss Scratch

verjin
New Scratcher
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.
deck26
Scratcher
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.
BT_Test
Scratcher
5 posts

Detect user input

Hi, Try this code that i wrote below
askEnter nameandwaitdeleteAllofNumberssetNumberIDto0repeat10addNumberIDtoNumberschangeNumberIDby1setCountto0setNumber detected ?to0repeatuntilNumberdetected?=1orCount=lengthofanswersetNum checkerto1repeat10ifletterCountofanswer=itemNumcheckerofNumbersthensetNumber detected ?to1changeCountby1ifNumberdetected?=1thensayNumbers detected !elsesayLetters only detected

Last edited by BT_Test (Aug. 8, 2019 18:03:52)

BT_Test
Scratcher
5 posts

Detect user input

BT_Test wrote:

Hi, Try this code that i wrote below
askEnter nameandwaitdeleteAllofNumberssetNumberIDto0repeat10addNumberIDtoNumberschangeNumberIDby1setCountto0setNumber detected ?to0repeatuntilNumberdetected?=1orCount=lengthofanswersetNum checkerto1repeat10ifletterCountofanswer=itemNumcheckerofNumbersthensetNumber detected ?to1changeCountby1ifNumberdetected?=1thensayNumbers detected !elsesayLetters only detected
Opps sorry i mistyped the codes above
askEnter nameandwaitdeleteAllofNumberssetNumberIDto0repeat10addNumberIDtoNumberschangeNumberIDby1setCountto0setNumber detected ?to0repeatuntilNumberdetected?=1orCount=lengthofanswersetNum checkerto1repeat10ifletterCountofanswer=itemNumcheckerofNumbersthensetNumber detected ?to1changeNum Checkerby1changeCountby1ifNumberdetected?=1thensayNumbers detected !elsesayLetters only detected
jacobsmash1
Scratcher
100+ posts

Detect user input

ifanswercontains0oranswercontains9oranswercontains8oranswercontains7oranswercontains6oranswercontains5oranswercontains4oranswercontains3oranswercontains2oranswercontains1thensayContains numbers!elsesayanswer
Very long or loop, idk if there is a better way to optimize it.
Devyev
Scratcher
5 posts

Detect user input

verjin wrote:

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.
first add numbers to a list
then add another list
add this code:
addletter1ofnumbertolist list1
addletter2ofnumbertolist list1
addletter3ofnumbertolist list1
addletter4ofnumbertolist list1
if list2containsitem1oflist list1?and list2contains?andthenbroadcastandwaitelsebroadcast d
sorry I cant finish
verjin
New Scratcher
6 posts

Detect user input

BT_Test wrote:

BT_Test wrote:

Hi, Try this code that i wrote below
askEnter nameandwaitdeleteAllofNumberssetNumberIDto0repeat10addNumberIDtoNumberschangeNumberIDby1setCountto0setNumber detected ?to0repeatuntilNumberdetected?=1orCount=lengthofanswersetNum checkerto1repeat10ifletterCountofanswer=itemNumcheckerofNumbersthensetNumber detected ?to1changeCountby1ifNumberdetected?=1thensayNumbers detected !elsesayLetters only detected
Opps sorry i mistyped the codes above
askEnter nameandwaitdeleteAllofNumberssetNumberIDto0repeat10addNumberIDtoNumberschangeNumberIDby1setCountto0setNumber detected ?to0repeatuntilNumberdetected?=1orCount=lengthofanswersetNum checkerto1repeat10ifletterCountofanswer=itemNumcheckerofNumbersthensetNumber detected ?to1changeNum Checkerby1changeCountby1ifNumberdetected?=1thensayNumbers detected !elsesayLetters only detected/quoteIusedthisanditalmostdidwhatIwanted.EverythingwasokbutItypedf4anditstill"Letteronlydetected".Doesanyoneknowhowtofixit?.ThishappenedthesamewithDevyevcode.Boththetwocodecannotdetectf4.f4stillhasnumber4init.Notonlyf4butanumberwithaletterwon'tworkquote=Devyevquote=verjinHelloIamhaving2issueswithmycurrentproject.IamexpectingwhenIinputnumbers,itwillsay"Pleasedon'ttypeinnumbers".Example:1234.IfIinputletterswithnumbersitwillsay"Invalidname".Example:r2d2.Thespritewillkeepaskinguntiltheuserinputonlyletters.WhatshouldIdonow?Iusedthecodefromascratcher,ifItypeinonlynumbersthenitsays"Pleasedon'ttypeinnumbers".IfIinputlettersonlyorletterswithnumbers,Itwillsaywhatyouhavejusttypein.Hereisthelink:https:scratch.mit.edu/projects/323577775Thosearemytwofinalissues.Thankyouforspendingyourtime./quotefirstaddnumberstoalistthenaddanotherlistaddthiscode:scratchblocksaddletter1ofnumbertolist list1/scratchblocksscratchblocksaddletter2ofnumbertolist list1/scratchblocksscratchblocksaddletter3ofnumbertolist list1/scratchblocksscratchblocksaddletter4ofnumbertolist list1/scratchblocksscratchblocksif list2containsitem1oflist list1?and list2contains?andthenbroadcastandwaitelsebroadcast d/scratchblockssorryIcantfinish/quote
verjin
New Scratcher
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
Scratcher
1000+ posts

Detect user input

verjin wrote:

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
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?

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
Scratcher
1 post

Detect user input

so how we can detect an input from an answer is using this code, here is an example.
whenclickedask"your question"andwaitifanswercontains"what you are trying to find"then

Powered by DjangoBB