Importing Code

In this activity, you'll incorporate blocks from other projects.
You first learned about importing blocks in Unit 1 Lab 7 Activity 7: Visualizing and Reflecting on Your Results.

Some blocks you've used are built into Snap!. For example:
map 'reporter input slot' over 'list input slot' repeat () {} join () ()

Other blocks you've used are custom blocks that were developed for this course. For example:
say hello to () in ('English') RGB pixel, red: (85) green: (170) blue: (255) ask ()

And you've created some blocks of your own that aren't built into Snap!. For example:
mystery song message () shifted by () responses only from survey 'list input slot'

When you want to use a block that isn't available in your current project, you can open a project where you already have that block, export it (save it to your computer), open the project where you want the block, and import it (upload it from your computer).

  1. Talk with Your Partner Review your project plan, and decide which blocks from other projects you'd like to import into this project.
    Here are some examples to consider: (List out all the custom blocks they've used or built so far.) Primitives Seen:

    Custom blocks they've seen:
    1.1: say hello to () in ('English') fancy () fancy letter ()
    1.2: Super Short Story, feeling: () job: () action: () place: () action: () number: () color: () plural animal: () food: () random feeling random job random action random place random color random food random animal
    1.3:
    1.4:
    1.5:
    1.6:
    1.7:

    Custom blocks they've built:
    2.1:
    2.2:

  2. Open the project that has the block (or blocks) you want.
  3. Export the blocks you want.
    1. Open the Snap! project from which you want to export blocks.
    2. Choose "Export blocks..." from the Snap! file menu (File menu button).
    3. Select only the block(s) you wish to export.

      You can either deselect the blocks you don't want exported, or you can right-click the background, choose "none," and then select only the ones you want.

      If you want to export a block that uses other custom blocks inside it, those blocks will be selected automatically, and you won't be able to deselect them unless you first deselect the block(s) that use them.

    4. Click "OK." An XML file will download to your computer.
  4. Open your Snap! project called "Sparks - Interactive Project".
  5. Import the blocks you want, test them and resolve any issues, and save.
    1. Open the Snap! project into which you want to import blocks (in this case, your "Sparks - Interactive Project" file).
    2. Import the XML file by dragging it from your downloads folder into the Snap! window.
      You can also import an XML file by choosing "Import..." from the Snap! file menu, locating the XML file on your computer, and clicking "Open."
    3. Test the blocks that you imported:
      1. Find the imported block(s) at the end of the palettes that contain them.
      2. Try out each imported block to make sure it runs properly.
  6. Repeat the process if you want blocks from other projects.
  7. Add the imported blocks to the code of your interactive project, and test that the project works as expected.
  8. Now Is a Good Time to Save
In this activity, you exported a block from another projects and imported it in your interactive project.