P4 - Ask Gobo
P4 - Ask Gobo
P4 - Ask Gobo
ASK GOBO
Ask Gobo
Do you have a tricky decision to make The green flag
Name of the project. starts the project. The red button
or want to predict the future? Let Gobo stops the project.
help you in this fortune-telling project.
Here you’ll learn about random numbers, ◁ Ask a question!
Ask Gobo
variables, and how computer programs by FortuneTeller100 (unshared)
Gobo works best if you ask
make choices. it to make predictions or
decisions for you. Don’t ask
factual questions as it’ll often
get the answer wrong!
◁ Gobo
Friendly Gobo is the only
sprite in this project. It has
three costumes that you Get ready to see
into the future!
can use later to help bring
it to life.
◁ Take a chance
Just as the roll of the dice
creates random numbers,
Scratch can generate
random numbers to
make the program react
in unpredictable ways.
1
Project 4
ASK GOBO
Start a new project. Then get rid Gobo’s answers should be spoken in a serious setting. Click
1 of the cat sprite by right-clicking 4 on the backdrop symbol in the lower-left corner of the 6 You need to add some more blocks to create
Gobo’s answer. Gobo will reply in one of two 8 A small window will pop up. Type
“ReplyNumber” into the box to name
on it and selecting “delete”. Scratch window and load the “greek theater” backdrop.
ways, which we’ll number one and two. the new variable and click “OK”.
Now drag Gobo to the centre with your mouse.
New Variable
Ask Gobo
Yes! No!
by FortuneTeller100 (unshared)
Variable name: ReplyNumber
info
For all sprites For this sprite only
duplicate
delete
OK Cancel
save to local file
ReplyNumber = 1 ReplyNumber = 2
Type the variable’s
name here.
To load the Gobo sprite, click on the
2 sprite symbol in the sprites list. The script will use a variable named “ReplyNumber” You’ll see that a block for your variable now
Choose Gobo and click “OK”. Gobo 7 to store the number of the reply the program has 9 appears in the Data blocks along with several
will now appear in the sprites list. chosen so it can show the correct message. To make other blocks.
a new variable, choose the orange Data blocks at
Select Gobo by clicking on it in the sprites list. Now add these the top of the blocks palette. It won’t have any If this tick box is ticked, the value
5 extra blocks to your script to make it speak when the project blocks in it yet, so click the “Make a Variable” button. of the variable is shown on the
stage. Leave it ticked for now.
starts. Run the new script and you’ll see that it pauses until
you press the space-bar. Gobo won’t answer yet.
2
Project 4
ASK GOBO
The script should now look like this. Run the project a
EXPERT TIPS 13 few times and check that Gobo gives random “yes” and
Random numbers “no” answers. If not, check the whole script carefully.
Wait! The answer
A random number is one that you can’t is coming to me...
predict before it appears. A dice roll is a
random number – any of the numbers 4 when clicked
1 Lowest number If you click on the
from one to six could appear each time
it can select block it will tell set size to 250 %
you roll the dice. You don’t know which you its value. It
number will come up until you roll. In selects a random
pick random 1 to 6 say I can answer your yes-or-no questions. for 3 secs
Scratch, you can get a random number number each time.
using the “pick random” block. Drag say Ask your question then press space.
this block into the scripts area and Highest number 6
experiment with it. it can select 3
wait until key space ▾ pressed?
“set ReplyNumber to” block to the bottom of Gobo’s script and set ReplyNumber ▾ to pick random 1 to 2
2
then drag a green “pick random” block into it from the Operators
section. Change the second number to two. The green block
if ReplyNumber = 1 then
picks randomly between one and two, like flipping a coin.
say Yes!
Change the second
set ReplyNumber ▾ to number to 2.
pick random 1 to 2
if ReplyNumber = 2 then
Next create this block to add to the
11 bottom of the script. It will make Gobo if ReplyNumber = 1 then say No!
say “Yes!” if the value in the variable
“ReplyNumber” is one. The “say” block say Yes!
only runs if the value is one, otherwise
it’s skipped.
You can now go to the Data blocks section
Connect this block to the
14 and untick the “ReplyNumber” block to
Scripts Costumes Sounds
3
Project 4
ASK GOBO
▽ Ask me another say I can answer your yes-or-no questions. for 3 secs
To make Gobo answer more questions after the say Ask your question then press space.
Should I be nicer first one, place the original script inside a “forever”
Should I do my to my sister? wait until key space ▾ pressed?
loop, as shown here, with a few extra blocks to
homework right away?
make Gobo prompt the user for a new question. say Wait! The answer is coming to me... for 3 secs
wait 1 secs
4
Project 4
ASK GOBO
Yes!
if ReplyNumber = 1 then
when clicked
wait 1 secs
if ReplyNumber = 3 then
set ReplyNumber▾ to pick random 1 to 5
Add four more “if then”
say Maybe... blocks. These are just This loop makes the horse
repeat ReplyNumber
suggestions – you can count out the answer by
choose your own replies. lifting its feet.
switch costume to horse1-b ▾
if ReplyNumber = 4 then wait 1 secs
Definitely!
say Definitely! switch costume to horse1-a ▾
wait 1 secs
if ReplyNumber = 5 then
▷ Do as I say!
if ReplyNumber = 6 then Rather than answering questions, Gobo could give Take a hike!