Building a Chatbot

In this lesson, you'll learn how to make a chatbot using Scratch, a block-based programming language. Head over to scratch.mit.edu to make an and start your adventure!

  • Types of Blocks

    • Block Types There are eight types of blocks in Scratch. Each type lets you control the game in a different way. You can also make your own blocks. For example, "Motion" blocks control the motion of an object, and "Looks" blocks control an object's appearance and some actions.
  • First Block

    • Starting a Game This is an example block of Scratch. When you click on a sprite, it will say two lines, each for two seconds. It is very easy to make blocks of code, as you just drag commands below other commands to connect them together. The code executes from top to down.
  • Function Blocks

    • Events Custom blocks called "functions" let you fit large and complex blocks of code into one small block for repeated use. In the above picture, two function blocks customly named "Chat" and "Guessing Game" can be coded to have their own uses.
  • Full Game

    • Tjhe Full Block Let's look at the function named Guessing Game, and it executes code that simulates a guessing game. When you "call" the function, or use it in other blocks of code, the contents of this function are performed! The step-by-step analysis of this block of code will be covered later.
  • Gameflow

    • The Ask Block The "ask" block is the essence of the chatbot. It allows users to input text, or in this case, questions for the robot. As shown, if what the user inputs includes the word guessing or game, the function called Guessing Game executes. Similar logic is used for the Chat function.
  • If Statements

    • If Block The if statement seen is just like how English works. If and only if a condition is fulfilled, the block inside it is executed.

      There are many other elements of scratch that we have not yet covered, but feel free to explore on your own! You can make amazing projects out of combinations of certain commands and blocks. Good luck!

Youtube Tutorial

Final Product

Built by Fragaria Webdev