Now that your program allows the user to draw, the next step is to turn it into a game.
This video will show you how to allow one player to draw and another to try to guess what the drawing is.
Click the monkey to start.
First, the game will ask player 1 what he or she plans to draw, and the player will type in an answer.
The game starts when the flag is pressed, so select the events menu, and drag out a "when flag clicked" block to start this code stack.
To ask the player a question and store an answer, use the "ask" block found in sensing.
Test this by clicking the flag.
The monkey asks the question, and a text box appears for player 1 to type an answer.
Click the stop sign to stop the program.
In the "ask" block, type a question for player 1 to answer.
This example asks, "What will you draw?"
Scratch stores the answer to this question in a variable called "answer."
Variable blocks have a round shape, and can store both numbers and words.
Click the checkbox next to "answer" to display the answer stored inside.
If you enter a word like, "banana," then the word banana gets stored inside the answer variable.
If you try again and enter something else, the new answer replaces the old.
Now, the second player needs to be able to guess what the drawing is.
Drag out another "ask" block.
Change the text to something like, "What do you think the drawing is?"
This block should only run after player one has drawn a picture.
An easy way to do this is to ask the question when the monkey sprite is clicked.
Add a "When this sprite clicked" event to the "ask" block.
Click the flag to try this out.
The monkey asks what player 1 is going to draw.
When player 1 types an answer, it is stored in the “answer” variable.
Then player 1 can draw something, and player 2 can click the monkey and type an answer when the monkey asks what the drawing is.
If player 2 types something other than what’s stored in “answer,” like "stick figure," it replaces what was stored in the answer variable.
This is a problem, because to find out if player 2 is right, the computer needs to know what the first answer was.
To fix this, make a new variable to store player 1’s answer.
Click data, and select "make a variable."
This variable will store the type of drawing made by player one, so call it something like "right answer," and click OK.
Notice that Scratch just created a set of variable blocks for you.
You need to store player one’s answer in this variable, so drag a "set right answer to" block below the first "ask" block.
Then, click sensing and drag an answer variable into this "set" block.
When you run the program and type a response, it is stored in the answer variable, *and* the "right answer" variable.
When player 2 types a response, it replaces the answer, but *not* the "right answer" variable that says what the correct answer is.
In the next video, you will check *if* player 2’s answer is the same as the right answer.
Now it’s your turn: Program the monkey to ask player 1 for a drawing when the flag is clicked, and player 2 to guess what the drawing is when the sprite is clicked.
Create a "right answer" variable, and set it to the first answer.
- Program the monkey sprite to ask player 1 for a drawing.
- Program the game so that player 2 can guess the drawing.
- Create a variable to store the right answer.