Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Hide and Seek


In this add-on, you’ll make the object appear in a random place each time the user plays the game. This makes the game less predictable and more fun.

In the core project, the object shows when the game switches to a specific backdrop.

Since the object should show on a random backdrop, select the object, detach the “when backdrop switches to” block, and delete it. Click the stage, then the “backdrops” tab. There are four different backdrops: one for the town, and one for each of the three locations. Each of these backdrops has a number. Click the “scripts” tab, then open the “looks” menu. Find the “backdrop number” block, and click it to see what it does.

This block outputs the current backdrop’s number.

Add this block to the “objects” sprite by dragging it on top. Then, click the “objects” sprite. Cool. The “backdrop number” block appears in the scripts area.

Click “data,” then click “make a variable.” A variable holds a value. In this case, this variable will hold a random backdrop number where the object will appear. Name the variable “object location,” then click “OK.” Set this variable to a random number. Drag out a “set object location” block, then place a “pick random” block from “operators” into it. Type “2” and 4” in the value spaces, because backdrops 2, 3, and 4 represent the three possible locations where the object can be found.

Test this block by clicking on it a few times. The value next to “object location” on the stage changes to a random number between 2 and 4 each time. Great! Place this block above the “forever” block, so the program decides where the object will hide at the start of the game. Next, build a conditional statement that checks if the current backdrop equals the object location. Drag out an “if” block. Place an “equals” block inside the condition slot. Click data, and drag the “object location” block into one slot, and the “backdrop number” block into the other.

If this statement is true, make the object show, then detect if the player is touching it. Put this conditional around the “touching character” conditional, and move the “show” block into the “if” statement. Add a “when flag clicked” block on top so this code runs when the flag is clicked.

Finally, open the “data” menu, and uncheck the box next to “object location.” This hides the variable display on the stage so the player can’t see the answer.

This code now reads: When the flag is clicked, set the object location to a random number between 2 and 4. If the current backdrop number is equal to that random number, meaning the character is at that location, then, the object shows.

Test it out by playing the game more than once. The object now appears at a random place each time. Now, it’s your turn!

Select the object sprite, and discard the “when backdrop switches to” block for the “touching character” conditional. Drag the “backdrop #” block from the stage into the “objects” sprite. Create a “object location” variable, and set it to a random number at the start of the program.

Build a conditional that checks if the backdrop number equals the object location variable.

If the condition is true, show the “object” sprite, and turn on the winning condition.

Choose an Add-On
Rearranging Furniture
Customize the look of each location.
Make the game more challenging by showing the object only if the character is nearby.
Code a Conclusion
Add some slides to end the story when the player wins.
Musical Objects
Add some interactive items that make sound when the character walks over them
Obstacle Obstruction
Make the maps more realistic by preventing the character from running into obstacles, like trees or buildings.
Hide and Seek
Hide the object in a random location each time.
arrow_backward Back
Next arrow_forward