Skip to content

Please update your browser

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

3. Your Job Will Be...

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 the last video.

Click on the code to see it work.

The jobs should flash until you press the spacebar.

Great.

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

If you press the spacebar, both a 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 the job 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 “message1,” 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, the home sprite starts switching costumes.

When you press the spacebar, 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 spacebar, the loop for the home stops running, and immediately tells the job to run.

It does this so fast, your hand is still pressing down the spacebar!

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 the green flag, and stop the homes from cycling with the spacebar.

The jobs start switching costumes.

Stop them with the spacebar 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 the message that a home has been selected.

Add a title and instructions to your project.

arrow_backward Back
Next arrow_forward
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.