Skip to content

Please update your browser

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


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.

Choisir une extension
Réagencer les meubles
Personnalise l'apparence de chaque lieu.
Augmente la difficulté du jeu en montrant l'objet uniquement si le personnage est à proximité.
Coder une conclusion
Ajoute des diapositives pour terminer l'histoire lorsque le joueur gagne.
Objets musicaux
Ajoute des éléments interactifs qui jouent un son lorsque le personnage marche dessus.
Obstruction par obstacle
Rends les cartes plus réalistes en empêchant le personnage de rentrer dans les obstacles tels que les arbres ou les bâtiments.
Cache l'objet dans un lieu aléatoire à chaque fois.
arrow_backward Retour
Suivant arrow_forward