Hi, I’m Maxwell. I’m a 4th grader and I love coding!
Hi, I’m Jangis and I’m a coding instructor with CodeSpeak Labs!
Welcome to our Scratch tutorial! Today we will be coding a trivia game using a platform called Scratch. For our project we'll use ChatGPT to create a list of questions, so that we don't have to!
Sooo… what is ChatGPT?
ChatGPT is an artificial intelligence (AI) website is "like a smart computer that can talk and write like a person, helping us with questions and conversations." (That's a quote straight from ChatGPT itself). The G in ChatGPT stands for GENERATIVE, meaning that its responses are original and have never been written before. Generative AI can create original stories, write poems, code, solve math problems, give you tips about life, etc.
Does that mean that you can tell ChatGPT to write an essay for you and essentially cheat, and tell your teacher that you wrote this piece of writing?
Yes, that's actually a big problem with Generative AI, and there are software and people that check for that type of plagiarism in all kinds of academic writing.
How can ChatGPT help us with making a trivia game on Scratch?
ChatGPT will come up with trivia questions/answers about a subject, so we can copy and paste them into our game. That way, we can focus on the design and code for our project, while ChatGPT helps with the content.
To get the best questions, we will use PROMPT ENGINEERING. Prompt engineering is designing inputs for generative AI to produce the most optimal outputs. I know that definition is hard to understand, so we asked ChatGPT to explain prompt engineering so that a 4th grader would understand: “Prompt engineering is like telling a computer what to do by using the right words and questions so it understands.”
For example, we gave this prompt to ChatGPT: “make 5 trivia questions about Among Us”. And it did give us the questions, but no answers. When we asked for the answers, they were in complete sentences and too long. To get the best output, we changed our prompt to this: “Write 5 trivia questions and write the answer below each question. Make the questions about Among Us, and phrase the answers in two words or less.” This gave us the output that we were looking for. The more detailed your prompt, the better the result.
Depending on the content and your intended purpose and audience, you might want to take ChatGPT's questions and answers as a first draft that you can work from; you might need to fact-check and re-write it.
Also remember-- if you're a kid, please check with your grown-up and ask for permission to use ChatGPT. With great power, comes great responsibility!
Alright! Now that we have our questions, let’s start coding! Below you’ll find an example of the game. To try out the game, click on the green flag and answer the questions!
Watch the videos below to follow along with me to build your own Trivia Game. I recommend pausing the video after each step to check that you have all the code.
Part 1: Drawing a character
To get to Scratch, go to scratch.mit.edu. You can sign in if you have an account, and if you don’t, you can sign up for free or just click the Create button at the top. Create will still be at the top for new Scratch users.
Hover over the new sprite button, and then click on the paintbrush to draw your character. For this game, you will need a character who will ask the trivia questions.
(Note: We demo how prompt engineering works in ChatGPT at the beginning of the video; if you already read through it thoroughly above, you can go straight to the 9:49 point in the video to get to the part using Scratch.)
Part 2: Code Game Setup
This part is all about coding the start of the game. We’ll tell the game to start timer and load the questions before the player agrees to play the game.
We’ll need to create two lists: a list of questions and a list of answers. We’ll copy and paste all our questions and answers from ChatGPT.
Pro tip: use shortcuts CTRL+C and CTRL+V to copy and paste the highlighted text! If you are on a Mac, you’ll need to use Command+C and Command+V.
Part 3: Display the Questions
Now that we've put the trivia questions in the game, we’ll need them to show up on the screen. We’ll do this with broadcast blocks. When the computer receives the message “next question”, it will ask the next question in the list. If the answer of the player is equal to the answer in the answers list, then we can increase score and increase timer so that the player has more time to answer the rest of the questions. In our version of the game, if the player gets a question wrong, they will lose time! If you want to make your game easier or harder, that is up to you.
Congratulations on successfully completing your very own trivia game!
As a bonus challenge, you can have ChatGPT create more questions! It can create as many questions as you want, or as many as you can copy/paste. The trivia questions can be about any subject that you want, just be sure to use good prompt engineering to get good questions.