Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
In this video, you'll program
the "exit" sprite to show, hide and change the backdrop.
This sprite will work similarly to the entrance sprites.
When the player's sprite enters a
new location, the exit sprite will show.
If the player's sprite touches the exit sprite,
the backdrop will change back to town
and the exit sprite will hide.
In computer science, you'll often run into problems
that are similar to ones you saw before, like this one.
This is a chance to reuse code
you've already written to approach a new problem.
To start, click the exit sprite.
Currently, there isn't any code for this sprite.
Click the house entrance sprite
and draw the when I receive when backdrop switches to
and when flag clicked block stacks into the exit sprite.
Click the exit sprite, then right click the scripts area
and click clean-up to automatically organize your code.
This code reads, when backdrop switches to town, show.
And when I receive hide entrances, hide.
But this sprite should do the opposite.
It should hide when the other sprites show
and it should show when the other sprites hide.
Switch the show and hide blocks.
After you make that change, the code reads
if touching character, switch backdrop to house.
If the exit sprite touches the player's sprite,
the backdrop should switchback to town.
Click the drop down, and change this value to town.
When the backdrop switches to town,
the entrance sprites shouldn't hide.
So remove the broadcast hide entrances block.
Try it out altogether.
Click the flag and move the character into the house.
The exit, which looks like a door appears.
Next, move the sprite to the exit and awesome!
The backdrop changes and the exit sprites hides.
Computer scientists often reuse previously written code
and they frequently change that code
to fit the needs of their current program.
In this video, you reused the code from
the location sprites but you had to change it
to accomplish a different but similar task.
Now it's your turn.
Copy the code from the house sprite to the exit sprite.
Exchange the show and hide blocks.
Change the switch backdrop value to town
and remove the broadcast block.