Skip to content

Please update your browser

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

Transcript

Your friend has a future place to live.

Next on the list, a job.

First, program the job to change costumes, just like you did for the home.

To make this easier, you can copy your code from the home sprite to the job sprite.

Click on the home sprite's code and drag it to the job sprite.

When you click on the job sprite, you should see the code stack that changed your sprite's costume in that last video.

Click on the code to see it work.

The jobs should flash until you press the space bar.

Great.

When you click on the green flag, the home and job starts cycling through costumes.

If you press the space bar, both the home and job are selected at the same time.

To heighten the suspense, make the code choose a home, then choose a job.

The job needs to wait until a home has been chosen before it starts cycling through options.

To tell a job when to when to start flashing, use the broadcast block.

The broadcast block allows sprites or the stage to tell each other when to run a code stack.

Click on the home sprite, then choose the broadcast block from the events menu, and place it under the repeat until loop.

To make the message say something more descriptive than message one, click on the dropdown, choose new message, and name the message something like, job.

Click OK.

This message will tell all the other things in your program that the home sprite is done choosing a future.

When the job sprite receives the message the home sprite sent, it can be programmed to react.

Click on the job sprite.

Detach the repeat until loop from the when flag clicked block, replace it with a when I receive block from the events menu.

Select job from the dropdown menu.

Test the code.

When you click on the green flag, home sprite starts switching costumes.

When you press the space bar, the homes stop flashing, but the jobs do not appear to start.

This is because the code is running really fast.

When you press the space bar, the loop for the home stops running, and it immediately tells a job to run.

It does this so fast, your hand is still pressing down on the space bar.

To fix this, add a wait block from the control menu between the repeat until loop and the when I receive block.

Change the value to something small, maybe 0.2 seconds.

Test it.

Click on the green flag, and stop the homes from cycling with the space bar.

The jobs start switching costumes.

Stop them with the space bar as well, it works!

To make the project your own, give the project a creative title, and add instructions so others know how to use your creation.

Now it's your turn.

Use the broadcast block to tell the jobs sprite it is time to start cycling through options.

Add code to the jobs sprite with the when I receive and wait blocks, so the jobs sprite has code to follow when it receives a message and a home has been selected.

Add a title and instructions to your project.

Instructions
  1. Drag the code from the homes sprite to the jobs sprite.
  2. Make the jobs start after a home has been selected by adding a "broadcast" block.
  3. In the jobs sprite, use a "when I receive" block with a "wait" block to make the jobs change.
  4. Add a title and instructions to your project.