Getting Started with Scratch For Second Life (S4SL)

 

1. Set up

  • Download S4SL
  • Launch S4SL by double clicking "Scratch for Second Life"
    • Due to a bug, you may have better results if you drag Scratch.image and drop it onto "Scratch for Second Life" rather than double-clicking the .app or .exe file
  • Log into Second Life
    • Resize your Second Life window so that it can be side by side with S4SL
      • To resize, drag it from the bottom right corner
      • Also, you can quickly switch between the two applications by pressing alt-tab (windows) or apple-tab (mac)

2. Make an Object

  • In Second Life, switch to build mode
    • click on the blue "build" button at the bottom of your screen
  • Create an object (a prim)
    • click the create button at the top of the edit window, pick a shape below that, then click the wand on the ground to create it

3. Make a Script

  • Switch back to S4SL
  • Start with a "hat" block
    • Click "control" to see the control blocks
    • Pick one of the first five of these orange blocks (like "when I am touched"), and drag it to the scripting area on the right.
    • These are the "hat" blocks. They are different ways to make a program run.
    • For example, "when I am touched" makes the blocks connected below run when you click on the object. Here's what the others do:
      • "When I receive" runs when you chat a particular message.
      • "When I collide" runs when an avatar bumps into the object.
      • "When I am created" runs when the script is first saved, and when the object is rezzed (like when it is pulled out of your inventory)
      • "Forever" runs over and over, ten times per second.
  • Add a command by snapping it onto the bottom of the stack
    • Most of the other blocks are commands.
    • For example, click on "looks" tab, and drag out a "say" block. You can change the text in the say block.
    • If you connect this below the "When I am touched" block, your object will say something when you touch it.
    • Experiment with other blocks!
    • You can also open up the sample projects that come with S4SL to get ideas.

4. Copy the script into your object

  • In S4SL, click the "copy linden script" button. This puts your code on the clipboard.
  • Switch back to SL
  • Create a new script for your object
    • In the edit window for your object, click more, click on the content tab, and click the"New Script..." button.
    • Double click on the "New Script" that appears.
    • A script window will open, and your object will run the default script (and say "Hello, Avatar")
  • Paste in your script
    • You want to replace the script that is there with the one you have on the clipboard
    • In the script window, select all, then paste, then save
      • If paste does not work, sorry! This is a bug that we are still working on. You can help us fix it by providing as much information as possible about the computer you are using. Here are some workarounds:
        • Paste into a text editor, select all, copy that text, and then paste into second life
        • Try a windows computer (so far we have only seen this problem on macs)
    • A quick way to do this is with the keyboard shortcuts
      • On windows: ctrl-a, ctrl-v, ctrl-s
      • On mac: apple-a, apple-v, apple-s
    • Once your script has saved, close the window and switch out of build mode
    • Now you can test your object. For example, click on it to see if it says something
    • Repeat! Try things out!

Things to make:

  • Plants that react to people passing by
  • A pet that does tricks when you give it chat commands
  • Toys that change color, spin, or turn invisible
  • A floor that reacts when you step on it
  • A house with doors and windows that automatically open and close
  • Interactive clothing or other crazy things you can attach to your body
  • Whatever else you can imagine!

Other fun stuff to try:

  • Use your own sounds: the sound block lets you can type in the name of a sound you want your object to play. You will need to put a sound with this exact name in the inventory of the object.
  • Make many: Try making a bunch of copies of your object, for example a whole floor made of "intelligent" tiles (like the image above showing the sample project "rainbow floor tile"). Just make a single tile, then shift-drag to copy one object, or even copy a group of selected objects.
  • Make things that communicate: Use "broadcast ..." and "when I receive ..." to make multiple objects communicate with each other (see the "door" and "rainbow floor tile" examples)
  • Memory: Use variables to store numbers in your object so it can remember things
  • Logic: Use the conditionals if and if-else to compare things to each other
  • Sharing code: To share code, you can try the "paste script" button. To use it:
    • In SL, open an existing object with S4SL code inside (say, created by another person who has made the scripts visible to you)
    • Open the LSL script window, select all, and copy it
    • In S4SL, click "paste script" to regenerate the blocks for that script
    • This is an experimental feature! Thanks to Jens Moenig for Squeak code to save and load scratch blocks in XML format. Any bugs introduced here are mine.
 

Things to watch out for (known issues):

  • The blocks in the "pen" category for drawing lines will not work unless your object has in its inventory a special object called "lineSegment." You can find out how to obtain this object at the S4SL blog.
  • If you rotate your object using SL build mode, the move and point-toward commands may not behave as you expect.
    • One workaround is to use these blocks only with objects that you have not manually rotated.
    • For shapes that you need to rotate, or for more complicated shapes, you can link together multiple objects. Just be sure to put your script into a prim that has not been manually rotated.
  • Special characters in variable names, broadcasts and when-I-receive may cause problems
  • Scripts that have multiple loops running simultaneously, especially with wait blocks, may not behave as you expect
  • Please do not resize the S4SL window (nothing will break, it will just look weird)