ST EK List:
No EK's found.

tell looks different now. --MF 9/8/18

Sprite Following a Sprite

The tell block image(s) need to be updated (see relevant piazza post). When we do this, we also need to remove the sidenote alerting users to the issue. The solution file probably needs to be updated too, and perhaps also images in the TG. Also search site for other instances of tell. --MF, 11/6/17

On this page, you will change the script so that the sprites don't move forever, but only repeat until they touch.

  1. Change Sprite(2)'s code to point towards Sprite only until it is touching Sprite. (The following instructions and animation show how.)
    1. Select Sprite(2) by clicking its button below the stage.
    2. Replace the forever block with a repeat until block.
    3. Drag touching ()? into the hexagonal space in the repeat until block. Set it to repeat until it is touching Sprite.
      Replacing code
  2. Do the same for Sprite. Change its code to follow your mouse only until it is touching Sprite(2).
  3. Test your program to see if it does what you want:
    • When you click green-flag button, Sprite (the gray one) should follow your mouse and Sprite(2) should keep turning to face Sprite.
    • If you bring Sprite close enough to touch Sprite(2), both sprites should stop moving.
  4. So far, Sprite(2) points toward Sprite, but doesn't move toward it. Add a line of code to Sprite(2)'s script so that it chases Sprite. Here's the idea:
    Fill the input slot in the move block with a tiny number (probably less than 1) so Sprite(2) doesn't catch Sprite too quickly.
    when green flag clicked{repeat until(touching(Sprite)){point towards(Sprite); move(tiny number here) steps}}
  5. Test your program a few times.
  6. Pair Programming Swap
  7. Right now, when the sprites meet, they just stop. Make them have a conversation when they stop. You can do that by adding code like this to Sprite(2)'s script. Make up your own conversation. You can use any language you can type.

    Sprite(2) does things itself. It also tells Sprite what to do and when to do it. This code puts Sprite(2) in charge of Sprite.

    Import Tools

    In the current version of snap, the tell block isn't installed automatically. Click on the File File menu icon menu at the top of the snap window and select "Import Tools." The tell block will appear toward the end of the Control palette. You'll need to import tools once into each new snap project where you need tell.
    Please note that the tell block looks slightly different than it does in this image. It is now a one-line block. This image will be updated soon.
    Simple dialogue about going to lunch
To prevent the two sprites from being stuck to each other unable to move, the sprites will need some space between them and some time apart before the chase starts. Blocks such as these may help.
go to x:(-200) y:(-50); wait (1) secs  & go to x:(200) y:(-50); wait (1) secs
Now Is a Good Time to Save
  1. Give the sprites costumes.
    You can use a picture from the Internet by dragging the picture into the costume area for that sprite.
  2. Change the background on the stage.
    change the background on the stage