P4 - Ask Gobo

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Project 4

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!

How it works I can answer your


Gobo invites you to ask a question and yes-or-no questions.
then answers with either “Yes” or “No”.
You can ask anything you like, from “Am
I going to be a billionaire?” to “Should I Gobo uses speech
play a computer game instead of doing bubbles to interact
with you when you
my homework?” Gobo pauses to look run the project.
like it’s thinking, but its answers are
actually pure chance. Ask your question
then press space.

◁ 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

Setting the scene Making random choices


Starting a project usually involves picking sprites and Computers are usually very predictable. Often, with
backdrops. Follow these steps to add the Gobo sprite the same code and inputs, you’ll get the same outputs,
to the project and to load a suitable backdrop to create but you don’t want that in this project. Gobo’s script
a grand setting for Gobo’s answers. will mix things up with some random numbers.

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.

Scripts Costumes Sounds ReplyNumber


Gobo This “say” block doesn’t have
when clicked a time limit so it stays until
the next “say” block. Motion Events set ReplyNumber ▾ to 0
Gobo’s a bit small, so add this script set size to 250 %
3 to make him bigger. Run the project
Looks Control
and see him grow. say I can answer your yes-or-no questions. for 3 secs Sound Sensing change ReplyNumber ▾ by 1
Pen Operators
say Ask your question then press space.
Data More Blocks This block is used
when clicked wait until key space ▾ pressed? to insert a value
into the variable.
set size to 250 % say Wait! The answer is coming to me... for 3 secs Make a Variable

Click in the window wait 1 secs Make a List


This is just a trick – the Click here.
and type 250. computer isn’t really listening!

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?

say Wait! The answer is coming to me... for 3 secs


The variable will hold the number of Gobo’s reply, but the
10 program needs a way to choose that number randomly. Add a 1
wait 1 secs

“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

bottom of Gobo’s script. remove the variable from the stage.


Motion Events
Now run the project a few times.
12 Around half the time Gobo will say if ReplyNumber = 2 then
If you use the offline
Looks
Sound
Control
Sensing
“Yes!” The other times it doesn’t say version of Scratch, don’t
anything. If you look at the top of the say No! forget to save your work Pen Operators
stage, you’ll see the “ReplyNumber” from time to time.
Data More Blocks
variable says one when you get “Yes!”
and two when you get no reply. Add
this extra block to make Gobo say Again, connect this
“No!” when the variable is two. ReplyNumber
block to the bottom Uncheck
of Gobo’s script. the tick box.

3
Project 4

ASK GOBO

Now try using your project


15 to answer some important
questions to predict the future! Hacks and tweaks
Will I get a puppy
for Christmas?
You can do much more with the random numbers
than simply answering yes-or-no questions.
Am I a brilliant Try exploring some of these possibilities.
programmer?

set size to 250 %

▽ 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

Insert the original set ReplyNumber ▾ to pick random 1 to 2


script here.
EXPERT TIPS if ReplyNumber = 1 then

More decisions say Yes!


when clicked
You’ve already seen how to use “if then” blocks There are three different green blocks you
containing questions to decide whether or can use to compare numbers, each with forever if then
ReplyNumber = 2
not to run lines of code. In this project, you a different job and symbol: = (equal to),
say No!
use green Operators blocks inside “if then” > (greater than), and < (less than). Programmers wait 3 secs
blocks to check the value of a variable. The call true-or-false decisions used inside “if then”
pale blue question blocks have “yes” or “no” blocks “Boolean conditions”. They are named say Press space to ask another question.
answers, but when you use the green blocks after the English mathematician George Boole
you should ask if what they say is true or false. (1815–1864). wait until key space ▾ pressed?

All the blocks can go


inside an “if then” block.
key space ▾ pressed? ▷ Special effects
You can alter Gobo’s replies to be more
fun. While you’re at it, why not make if ReplyNumber = 2 then
touching Balloon1 ▾ ? True only if the
Gobo change colour or costume for each
if then variable “Age”
has a value of 10. reply? You could also add sounds to its say How DARE you ask that!
code to run replies, some dance steps, or a spin.
Age = 10
True only if the switch costume to gobo-c ▾
variable “Age” has a
Age > 5 value greater than 5. set colour ▾ effect to 50
How DARE you
ask that!
play sound scream-female ▾
True only if the
Age < 18 variable “Age” has
a value less than 18.

4
Project 4

ASK GOBO

▽ More replies ▽ Counting horse


To add to the fun you can extend the number of replies. You simply need You don’t have to stick to yes-or-no answers – instead, you
to increase the top number in the “pick random” block to the new number could answer questions like “How old am I?” or “What’s my Don’t forget to click the
of choices and then add extra “if then” blocks containing new “say” blocks. Change the 2 into a 6. This must IQ?” with random numbers. Start a new project, load the full-screen symbol
This example has six possible answers, but you can add as many as you like. match your number of replies or Horse1 sprite, and add the script below to make it count above the stage!
some responses will never appear. out the answers by stomping up and down with its feet.
You could also add some horse noises from the sound library.
set ReplyNumber ▾ to pick random 1 to 6

Yes!
if ReplyNumber = 1 then
when clicked

say Yes! switch costume to horse1-a ▾

say I can answer your number questions. for 3 secs

say Ask your question then press space.


if ReplyNumber = 2 then
No!
wait until key space ▾ pressed
say No! Maximum number
say Wait! The answer is coming to me... for 3 secs the horse can say

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

Never! say ReplyNumber


say Never!

▷ Do as I say!
if ReplyNumber = 6 then Rather than answering questions, Gobo could give Take a hike!

To make Gobo seem


random orders, such as “run up and down the stairs”,
say Tuesday! more mysterious, you “jump in the air twice”, or “sing a famous song”. Just
can include some change the text in the “say” blocks to Gobo’s commands.
strange answers. You could also change Gobo’s appearance to something
grumpy to match the mood.

You might also like