Creating interactive mad libs in Scratch

Hide and Show Variables

Listing 2 hides all the Stage monitors, and the last block in the stack assigns the sound4 variable a value of 0. The script in Listing 3 then checks the value of sound4. This error-handling check prevents the user from displaying the story before all the words are collected. The when Sprite1 clicked block (Listing 3) makes the cat clickable and is a user-initiated way to advance the story.

Listing 2: Cat Sprite Hiding Variables
Listing 3: Displaying the Story

After the script collects the four words from the user, the cat instructs the user to click on it to create and display the story. The script checks to see if sound4 is equal to 0. If that statement is true, nothing will happen when the user clicks on the cat, as represented by the empty if statement. If sound4 is not 0, then the cat hides while enabling all the reporter blocks so that the words stored in the variables display on the Stage. A create story broadcast is fired off and received by all 12 story sprites simultaneously.

Create Story

When each sprite in the story receives the create story broadcast, it will show itself; then, the sprite will hide itself when the user starts the project by clicking the green flag:

After you create a script for one story sprite, you can copy the script to other sprites by dragging and dropping it onto each of the 11 other story sprites. As you run through the story a few times, you can adjust the spacing of the sprites and the Stage monitors to try to create a readable story, regardless of what the user enters.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content