Sunday, July 13, 2008

A Script Generator for Second Life

Anyone who scripts in Second Life knows that the scripting language has a pretty steep learning curve, especially if you are not used to event driven programming. So it would be nice to have a code generator-maybe something a novice could use. Well today a post on SLED, the Second Life Educator's list, had a brief mention of a system called Scratch for Second Life (S4SL).

S4SL can be down loaded for Macs and Windows machine. I tested the Windows version on my home Vista machine and hope to test the Mac version on my iMac at work later this week.

S4SL is developed by Eric Rosenbaum at MIT, using Scratch . Scratch allows you to program graphically by snapping together little "modules." It sounds like a lot of fun in itself! But getting back to S4SL, the program has 8 classes of modules including one called pen which apparently requires an extra set of tools. Here is the opening window loaded along side the Second Life client. The left hand part of the window shows the eight modules, and the shapes associated with motion commands.

opening screen

Click on the image to go to my Flickr stream to see a large version of this screen. The basic idea is to snap together modules in S4SL. Then you press the copy code button. This copies the generated SL script into your clip board. So all you need to do is to rez an object SL, and paste the code in place of a new script.

S4SL is loads of fun and I spent a delightful evening making little Second Life "pets" that follow my Avatar around. The next image shows a Scratch program for a pet that exhibits random motion, but then attempts to find my avatar if it gets too far away.


The "modules" are color coded based on function and notice how the "modules" can be snapped together. This sort of approach ought to be appealing for novice programmers including biology types who are of course used to thinking of shape as related to function.

There are some limitations to S4SL. First, since it is in development, only some of the capabilities of SL's language are implemented. The code is fat, meaning there is a lot of non functional material in the code depending what sorts of features are enabled or disabled. Also the resulting code, because not everything is implemented may not work the way the user expects.

Originally I pasted the script into a cube prim for testing but it so happened I had a flexi prim representation of a phospholipid hanging around and I thought it would make a cool bacterium complete with flagella. So here is a brief movie (A still is here) of the resulting "bacterial cell:"

I think S4SL has a lot of potential as a learning tool. For instance someone interested in behavior could use the system, as my example suggests, let students design bots which mimic different sorts of orientation behavior. Students without any programming experience can give their simple prims behaviors and there are good pre-made S4SL projects that come with the down load to show how this can be done.

S4SL, a neat learning tool and lots of fun and it doesn't require any scratch for the fun.


ericrosenbaum said...

Thanks for your excellent post! I'm excited to see S4SL starting to get out into the world. I'd love to hear more as people try it out. Feel free to get in touch with me!

Paul D. said...


What would be cool is have a module for detecting not just the avatar and owner but also other objects. Maybe its there and I am just missing it. Could do that by tinkering with the script generated by S4SL I think but that would be a nice function. Here I am think of ALife applications.

ericrosenbaum said...

Interesting idea. I thought about this idea early on, but discarded it because it is probably error-prone. Basically, your script needs to know the name of the other object. S4SL doesn't know about objects in SL, so the user would have to type the name in, and you could easily get this wrong, which might be frustrating. In general, the scratch design philosophy has included preventing errors like this as much as possible... on the other hand, this would add some power that would be very cool! Artificial life like you say, but lots of other stuff too. It would pretty easy to add... I'll add it to the list of feature requests.

Anonymous said...

so, does scratch work?

Anonymous said...

Eric its so thoughtful of you to create Scratch but wht abt those ppl who dont even know how to script and/or what is a script

Is there a website where these newbies can find the scripts??