<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Creating_a_Chat_Bot</id>
	<title>Creating a Chat Bot - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://digida.mgpu.ru/index.php?action=history&amp;feed=atom&amp;title=Creating_a_Chat_Bot"/>
	<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Creating_a_Chat_Bot&amp;action=history"/>
	<updated>2026-04-09T03:53:26Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Creating_a_Chat_Bot&amp;diff=1648&amp;oldid=prev</id>
		<title>Patarakin: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Creating_a_Chat_Bot&amp;diff=1648&amp;oldid=prev"/>
		<updated>2022-07-21T08:33:13Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 11:33, 21 июля 2022&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;4&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;!-- diff cache key digida:diff:1.41:old-1647:rev-1648 --&gt;
&lt;/table&gt;</summary>
		<author><name>Patarakin</name></author>
	</entry>
	<entry>
		<id>http://digida.mgpu.ru/index.php?title=Creating_a_Chat_Bot&amp;diff=1647&amp;oldid=prev</id>
		<title>scratch&gt;Jonathan50: Somebody else made an AF page but didn&#039;t add the template to the original. :)</title>
		<link rel="alternate" type="text/html" href="http://digida.mgpu.ru/index.php?title=Creating_a_Chat_Bot&amp;diff=1647&amp;oldid=prev"/>
		<updated>2022-04-01T22:13:13Z</updated>

		<summary type="html">&lt;p&gt;Somebody else made an AF page but didn&amp;#039;t add the template to the original. :)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{April Fools}}&lt;br /&gt;
A chat bot is a program which allows mock communication with the computer or application. This can be developed by solely using [[Scratch]]; it involves many lists, operators, and the &amp;lt;sb&amp;gt;ask [] and wait&amp;lt;/sb&amp;gt; block in particular. This tutorial shows how to make one.&lt;br /&gt;
&lt;br /&gt;
==Brief Description==&lt;br /&gt;
To create a chat bot, the &amp;quot;[[Ask () and Wait (block)|ask]]&amp;quot; block needs to be used to enter a message. Then, the [[project]] takes that message, breaks it apart into words, and scans the list of words for specific words. Then, if the message contains those specific words, the chat bot can respond a pre-set message. To break apart the [[Answer (value)|answer]] [[variable]] into words, each letter must be repetitively added to a list until a space is reached, and then create a new item in the list and continue adding the letters, forming words. To program this, only one [[list]] will be needed:&lt;br /&gt;
* words&lt;br /&gt;
and one or two [[variable]]s:&lt;br /&gt;
* &amp;lt;sb&amp;gt;(letter #)&amp;lt;/sb&amp;gt;&lt;br /&gt;
* &amp;lt;sb&amp;gt;(pick)&amp;lt;/sb&amp;gt;&lt;br /&gt;
{{note|The variables and lists can have arbitrary names.}}&lt;br /&gt;
&lt;br /&gt;
==Programming the Bot==&lt;br /&gt;
The following code replication can be used to make the bot respond to messages. All these scripts can go in any sprite.&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
forever&lt;br /&gt;
ask [type a message] and wait&lt;br /&gt;
set [letter # v] to [1] //so the iteration begins with the first letter of the answer&lt;br /&gt;
delete all of [words v] //clears the list of words; the first step is separating the words into a list&lt;br /&gt;
insert [] at (1 v) of [words v] //it needs a blank item to start out&lt;br /&gt;
repeat (length of (answer)) //one repetition for each letter&lt;br /&gt;
if &amp;lt;(letter (letter #) of (answer)) = [ ]&amp;gt; then //note that a space is inserted into this string, not nothing&lt;br /&gt;
insert [] at (1 v) of [words v] //since it is a space, create a new item&lt;br /&gt;
else&lt;br /&gt;
replace item (1 v) of [words v] with (join (item (1 v) of [words v]) (letter (letter #) of (answer))) //otherwise, add the letter to the current word&lt;br /&gt;
end&lt;br /&gt;
change [letter # v] by [1] //move on to the next letter&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;[words v] contains [hello]&amp;gt; then //word detection&lt;br /&gt;
say [Hello to you, too!] for (2) secs//response&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;[words v] contains [like]&amp;gt; then&lt;br /&gt;
set  [pick v] to (pick random (1) to (2)) //for use in alternate responses&lt;br /&gt;
if &amp;lt;(pick) = [1]&amp;gt; then&lt;br /&gt;
say [I like that, too!] for (2) secs&lt;br /&gt;
else&lt;br /&gt;
say [Really? I don&amp;#039;t like that too much.] for (2) secs&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
For example, if &amp;quot;I like Scratch&amp;quot; is entered, the bot may respond &amp;quot;I like that too!&amp;quot; or &amp;quot;Really? I don&amp;#039;t like that too much&amp;quot; because the list of words contained &amp;quot;like&amp;quot;. The script can be made more complex by breaking it down into individual likes and more responses. The &amp;quot;pick&amp;quot; variable is used solely for making it respond one of multiple possible messages. However, if for instance, &amp;quot;I like Scratch&amp;quot; is typed in, the bot may respond &amp;quot;I like that too!&amp;quot;, but if it is typed in again, it might say &amp;quot;Really? I don&amp;#039;t like that too much.&amp;quot;. To prevent this, some lists can be made to store words that the bot already responded to.&lt;br /&gt;
&lt;br /&gt;
Make two [[lists]]:&lt;br /&gt;
* Likes&lt;br /&gt;
* Dislikes&lt;br /&gt;
&lt;br /&gt;
Then change this part of the script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
if &amp;lt;[words v] contains [like]&amp;gt; then&lt;br /&gt;
set  [pick v] to (pick random (1) to (2)) //for use in alternate responses&lt;br /&gt;
if &amp;lt;(pick) = [1]&amp;gt; then&lt;br /&gt;
add (item (join (last) ()) of [words v]) to [Likes v]&lt;br /&gt;
else&lt;br /&gt;
add (item (join (last) ()) of [words v]) to [Dislikes v]&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;(pick) = [1]&amp;gt; then&lt;br /&gt;
if &amp;lt;not &amp;lt;[Likes v] contains (item (last v) of [words v])&amp;gt;&amp;gt; then&lt;br /&gt;
say [I like that, too!] for (2) secs&lt;br /&gt;
else&lt;br /&gt;
delete (last v) of [Likes v]&lt;br /&gt;
say [Didn&amp;#039;t I already tell you I liked it?] for (2) secs&lt;br /&gt;
end&lt;br /&gt;
else&lt;br /&gt;
if &amp;lt;not &amp;lt;[Dislikes v] contains (item (last v) of [words v])&amp;gt;&amp;gt; then&lt;br /&gt;
say [Really? I don&amp;#039;t like it too much.] for (2) secs&lt;br /&gt;
else&lt;br /&gt;
delete (join (last) ()) of [Dislikes v]&lt;br /&gt;
say [Didn&amp;#039;t I already tell you I didn&amp;#039;t like it?] for (2) secs&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{note|This might not work if there is more than one word after &amp;quot;like&amp;quot;}}&lt;br /&gt;
&lt;br /&gt;
===Final Product===&lt;br /&gt;
Excluding scripts in the next section, the whole script would be something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
when gf clicked&lt;br /&gt;
forever&lt;br /&gt;
ask [type a message] and wait&lt;br /&gt;
set [letter # v] to [1] //so the iteration begins with the first letter of the answer&lt;br /&gt;
delete all of [words v] //clears the list of words; the first step is separating the words into a list&lt;br /&gt;
insert [] at (1 v) of [words v] //it needs a blank item to start out&lt;br /&gt;
repeat (length of (answer)) //one repetition for each letter&lt;br /&gt;
if &amp;lt;(letter (letter #) of (answer)) = [ ]&amp;gt; then //note that a space is inserted into this string, not nothing&lt;br /&gt;
insert [] at (1 v) of [words v] //since it is a space, create a new item&lt;br /&gt;
else&lt;br /&gt;
replace item (1 v) of [words v] with (join (item (1 v) of [words v]) (letter (letter #) of (answer))) //otherwise, add the letter to the current word&lt;br /&gt;
end&lt;br /&gt;
change [letter # v] by [1] //move on to the next letter&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;[words v] contains [hello]&amp;gt; then //word detection&lt;br /&gt;
say [Hello to you, too!] for (2) secs//response&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;[words v] contains [like]&amp;gt; then&lt;br /&gt;
set  [pick v] to (pick random (1) to (2)) //for use in alternate responses&lt;br /&gt;
if &amp;lt;(pick) = [1]&amp;gt; then&lt;br /&gt;
add (item (join (last) ()) of [words v]) to [Likes v]&lt;br /&gt;
else&lt;br /&gt;
add (item (join (last) ()) of [words v]) to [Dislikes v]&lt;br /&gt;
end&lt;br /&gt;
if &amp;lt;(pick) = [1]&amp;gt; then&lt;br /&gt;
if &amp;lt;not &amp;lt;[Likes v] contains (item (join (last) ()) of [words v])&amp;gt;&amp;gt; then&lt;br /&gt;
say [I like that, too!] for (2) secs&lt;br /&gt;
else&lt;br /&gt;
delete (last v) of [Likes v]&lt;br /&gt;
say [Didn&amp;#039;t I already tell you I liked it?] for (2) secs&lt;br /&gt;
end&lt;br /&gt;
else&lt;br /&gt;
if &amp;lt;not &amp;lt;[Dislikes v] contains (item (join (last) ()) of [words v])&amp;gt;&amp;gt; then&lt;br /&gt;
say [Really? I don&amp;#039;t like it too much.] for (2) secs&lt;br /&gt;
else&lt;br /&gt;
delete (join (last) ()) of [Dislikes v]&lt;br /&gt;
say [Didn&amp;#039;t I already tell you I didn&amp;#039;t like it?] for (2) secs&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Taking it Further==&lt;br /&gt;
To make the chat bot more realistic, a separate list of previously stored words can be created from old entered messages, and make the bot refer to those later in the conversation. For example, if it is told that the user likes programming, and then is later told that the user likes Scratch, it can relate the two using the list of old words and say &amp;quot;Of course you like Scratch, you like programming&amp;quot; by sensing if the list of old words contains &amp;quot;programming&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The script could also be changed to make the bot understand even more words, using this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;scratchblocks&amp;gt;&lt;br /&gt;
if &amp;lt;[words v] contains [Word you would like bot to understand]&amp;gt; then //word detection&lt;br /&gt;
say [Response you would like your bot to say] for (2) secs//response&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/scratchblocks&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
* [[Separating a String into Words]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scripting Tutorials]]&lt;br /&gt;
[[Category:Game Design Tutorials]]&lt;/div&gt;</summary>
		<author><name>scratch&gt;Jonathan50</name></author>
	</entry>
</feed>