Discuss Scratch
- Discussion Forums
- » Show and Tell
- » [FIXED] How to Create A Working AI Chatbot With This Simple Asset!
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
Fingers crossed this formats correctly lol)
ChatGPT and other AI chatbots are pretty cool, and take lots of advanced text coding.
While you can't realistically make a web-connected intelligent chatbot on Scratch, you can create an easy-to-use chatbot platform that mimics these abilities and is able to answer a question with pre-set answers. Sure, it isn't AI perse, but it behaves just like one!
Here's how you can do it without a crazy number of blocks!
First, start with the basics: asking the question.
How do you want your chatbot to be activated? How about when Space key is pressed as an example?
Great. Now we want the user to be able to ask their question, or input.
Let's add an ask block to our space key block. Type what the chatbot should say when requesting information.
Okay, so now the chatbot collects the info, but does not do anything with it after.. Let's fix that.
Create a variable:
Let's set this variable to the query. (You won't be using this variable is this tutorial, but if you decide to advance your chatbot after this, this can be really helpful!!)
Now we've collected the answer. If you check the variable after asking the chatbot, the variable will be equal to the input! Amazing!
Well…almost amazing. The chatbot doesn't answer the question yet : /
You could just create a bunch of these blocks:
But that's time-consuming and makes it hard to work through your code.
How about we use lists to put this all together? That's better!
Let's create a custom block (the color may be red, but should be pink lol):
Now let's define this block. Start by creating two variables, ID
and Match
Now to actually define the block! First, let's clear these variables by setting them to blank.
Now we need to make two lists, Query and Ans.
In Query, type what the user should search (or what the search should contain for a specific answer).
For instance, add “Hello” as item 1 and “Bye” as item 2 to the list.
Then, add to Ans the responses (or the output) on the same number that the input is on. So, add in something like “Hello there! How may I help you today?” as item 1 and “See you again soon!” as item 2.
Great, now let's allow the AI to search the lists for answers.
Add the repeat block to the bottom of Search but with “length of Query” replacing “10”. This is so each query match is checked to see if the input contains it.
end
Then, add into the repeat block:
Put it all together!
This little but powerful script searches for a matching query by individually reviewing each item in the query list.. Now let's match it with the answer!
Back to our main block, add Search.
Let's make one more variable:
Then add this block:
Last, add the say block to announce the answer.
Success! You've created a chatbot that compares queries to pre-set answers and responds to the user with them!
It can check for answers and if it doesn't know, it'll say so!
I hope this helped you and your coding!
If you use this, credit would be appreciated but not required of course.
Thanks for reading all this lol ^-^
ChatGPT and other AI chatbots are pretty cool, and take lots of advanced text coding.
While you can't realistically make a web-connected intelligent chatbot on Scratch, you can create an easy-to-use chatbot platform that mimics these abilities and is able to answer a question with pre-set answers. Sure, it isn't AI perse, but it behaves just like one!
Here's how you can do it without a crazy number of blocks!
First, start with the basics: asking the question.
How do you want your chatbot to be activated? How about when Space key is pressed as an example?
when [space v] key pressed
Great. Now we want the user to be able to ask their question, or input.
Let's add an ask block to our space key block. Type what the chatbot should say when requesting information.
when [space v] key pressed
ask [What is your question?] and wait
Okay, so now the chatbot collects the info, but does not do anything with it after.. Let's fix that.
Create a variable:
(userInput)
Let's set this variable to the query. (You won't be using this variable is this tutorial, but if you decide to advance your chatbot after this, this can be really helpful!!)
when [space v] key pressed
ask [What is your question?] and wait
set [userInput v] to (answer)
Now we've collected the answer. If you check the variable after asking the chatbot, the variable will be equal to the input! Amazing!
Well…almost amazing. The chatbot doesn't answer the question yet : /
You could just create a bunch of these blocks:
if <(userInput) contains [Hello]?> then
say [Hello there!]
end
But that's time-consuming and makes it hard to work through your code.
How about we use lists to put this all together? That's better!
Let's create a custom block (the color may be red, but should be pink lol):
Search
Now let's define this block. Start by creating two variables, ID
(ID)
and Match
(Match)
Now to actually define the block! First, let's clear these variables by setting them to blank.
define Search
set [Match v] to []
set [ID v] to []
Now we need to make two lists, Query and Ans.
(list :Query: list)
(list :Ans: list)
In Query, type what the user should search (or what the search should contain for a specific answer).
For instance, add “Hello” as item 1 and “Bye” as item 2 to the list.
Then, add to Ans the responses (or the output) on the same number that the input is on. So, add in something like “Hello there! How may I help you today?” as item 1 and “See you again soon!” as item 2.
Great, now let's allow the AI to search the lists for answers.
Add the repeat block to the bottom of Search but with “length of Query” replacing “10”. This is so each query match is checked to see if the input contains it.
repeat (length of [Query v] :: list)
end
Then, add into the repeat block:
change [ID v] by (1)
if <(answer) contains (item (ID) of [Query v] :: list)?> then
set [Match v] to (item (ID) of [Query v] :: list)
end
Put it all together!
define Search
set [ID v] to []
set [Match v] to []
repeat (length of [Query v] :: list)
change [ID v] by (1)
if <(answer) contains (item (ID) of [Query v] :: list)?> then
set [Match v] to (item (ID) of [Query v] :: list)
end
end
This little but powerful script searches for a matching query by individually reviewing each item in the query list.. Now let's match it with the answer!
Back to our main block, add Search.
when [space v] key pressed
ask [What is your question?] and wait
set [userInput v] to (answer)
Search
Let's make one more variable:
(Complete)
Then add this block:
if <(Match) = []> then
set [Complete v] to [I don't know that answer yet.]
else
set [Complete v] to (item ((item # of (Match) in [Query v])) of [Ans v] :: list)
end
Last, add the say block to announce the answer.
say (Complete)
Success! You've created a chatbot that compares queries to pre-set answers and responds to the user with them!
It can check for answers and if it doesn't know, it'll say so!
I hope this helped you and your coding!
If you use this, credit would be appreciated but not required of course.
Thanks for reading all this lol ^-^
Last edited by HollyEuca (Nov. 15, 2025 16:57:50)
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
Some of the formatting isn't perfect I'm trying to fix it rn : P
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
Sorry about the random red V letters! Please ignore them. Everything else seems ok.
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
Ok i fixed lol i hope it helps your coding 

- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
bump
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
Sorry that the lists appear as variables lol, they are supposed to be dark-orange : P
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
bump
- HollyEuca
-
Scratcher
1000+ posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
bump
- 33tomolol
-
Scratcher
41 posts
[FIXED] How to Create A Working AI Chatbot With This Simple Asset!
It dosn't work anymore
- Discussion Forums
- » Show and Tell
-
» [FIXED] How to Create A Working AI Chatbot With This Simple Asset!