revUp - Updates and news for the LiveCode community
Issue 104 | Feb 10th 2011 Contact the Editor | How to Contribute

Compile-free Coding for Second Life
A real life virtual world example of LiveCode in action

by Paladin Pinion

[Editors Note: It was brought to my attention that one of the more popular software programs available for Second Life afficionados was actually written in LiveCode. Being curious, I managed to catch up with the creator. He/she/it agreed to an interview on the making of Mote, on condition that their "real world" alter ego was not revealed... ]

Mote

Who is Paladin Pinion?

I'm a phoenix, though sometimes I turn into an egg when I want to be left alone. I usually hang out in my treehouse in Second Life, where I build and create scripted items and sometimes indulge in random conversations with my AI bug cannon. He's only about half smart but after a long day of building and scripting you appreciate almost any kind of interaction. I also have a shop in the mall at Zimmy's Zurelia where I sell my products, and a presence on the Second Life Marketplace. In fact, everyone should go purchase my things so I can pay my rent. It seems like my rent is always due.

I'd tinkered with programming in this life cycle iteration, so naturally after discovering Second Life I became interested in their scripting language, LindenScript. It's a lot like C in form and function, and limited in some respects, but it does work. After some experiments with various things, I got interested in their particle system and eventually used LiveCode to write a little application called Mote, which creates particle scripts for Second Life.

... er... right....what's a particle script?

I guess the first thing to answer is "what's a particle?" Particles are moving sprites used for all sorts of things in Second Life, like rain, clouds, explosions, fireworks, exhaust plumes, mist, water fountains, firefly lights, jewelry bling...well, let's just say particles are everywhere over there.

Particles are controlled by a single LindenScript command which has between a bunch and a half-zillion parameters. The syntax is moderately complex, and while it isn't too awfully hard to learn if you study and pay attention, it is tedious to work with. In response, lots of people have written particle script generators to make the task easier. These gizmos determine how you want your particles to behave and then create a LindenScript to do it. There are dozens of them on the SL Marketplace, though none are like Mote by a long shot.

What led you to write it?

Well, I didn't know there were others on the market when I started, I just wanted to write a tool for myself. It was only later that I figured it would be useful to others too. I started looking around and saw that none of the available products did what I wanted. They all suffered from interface failures, mostly because SL doesn't have any decent input options. There are no text fields, option or combo buttons, or any other controls that computer users expect, so every script generator out there was compromised because of these limitations.

There is one other software-based particle script generator, but it is Windows-only and, to my ancient eyes, a little ugly. It also doesn't have half the options that Mote has.

What sets Mote apart?

By moving the generator to real software, all the above limitations disappear. And Mote is the only script generator available for all three major operating systems, thanks to LiveCode's easy compiling options. It's also the only product that has any documentation to teach you the particle system.

You don't have to worry that SL will lose your scripts (which does happen) because they are stored as files on your own computer, and they can be saved, re-opened, imported, and exported as you'd expect. Mote is the only script generator that can import particle scripts for re-use. You aren't limited to copying a few lines of script at a time from a chat window because the whole script is not only displayed at once (in a real text field! imagine!) but is also auto-copied to the clipboard. And with Mote 2.0, you don't need to open a Second Life script editor or compile anything unless you want to. You don't even have to look at a script.

preferences

One big plus is mostly due to LiveCode's seamless integration with the operating system. Mote can plug into the OS for native controls and behaviors; for example, it lets you choose colors using the system color picker, uses native OS popup menus and input fields, provides real system windows for preferences and playlists, auto-copies text, and other things that are impossible in Second Life gadgets. LiveCode lets you do all that with minimal or no scripting at all. Mote can also auto-convert degrees to radians, auto-fill common parameters, save your preferences (SL gadgets can't save much of anything) and do dozens of other little tasks that would be much harder within the limitations of LindenScript. Lindenscript is pretty terrible at string parsing, for example, and Mote has to work extensively with strings. LiveCode's string manipulations are almost embarrassingly easy. LiveCode makes you look pretty clever.

Why was LiveCode the right choice for creating Mote?

Mostly the speed of development, cross-platform support, and ease of coding. I wrote the actual script-generation code for Mote 1.0 in under a day, and then spent the rest of the week making a nice interface. The other particle script generators I looked at seemed confusing and busy to me, and I wanted to avoid that. I wanted something clean and simple, with all the complexity hidden under the hood. I think I managed that.

Another big draw for LiveCode is that there is no code-compile-test cycle like most other development systems. With LiveCode, testing and debugging is a single smooth operation. The OS-native appearance of all the card controls was also a plus, because there was very little I needed to do to make each app look like the OS it was built for. It really is write-once development.

Also, there's the string manipulation thing. You just can't do that any easier than in LiveCode.

How is Mote doing?

Pretty well. Mote 1.0 was popular enough that it got pirated and distributed on the warez sites. And then someone took that pirated version and started selling it on the Second Life Marketplace for the equivalent of about $1.50, pretending he was me and undermining my sales. He even promised his customers free updates for life, in spite of the fact that the version he was selling was four updates behind and he didn't have the source code - thanks in large part to LiveCode's secure code scrambling.

I considered handing him over to Hydra, but I'm basically gentle by nature so I submitted a DMCA takedown notice and Linden Labs removed his listing and terminated his account. You'd think at my age I'd be used to idiots, but I still walked around with little particle clouds over my head for a while. I even thought about hopping into the fire and regenerating early. The soothing forgetfulness of Lethe and all. But sales picked up again after that so I forgot about forgetting.

There's not much you can do except move on after something like that, so I wrote version 2.0. In the long run it was for the best, because the software is much better now and it overcomes a previous limitation, which was the lack of real-time interaction with Second Life. Now Mote and Second Life talk to each other.

How does that work?

Mote 2.0 - "Mote Remote" - communicates with Second Life objects via HTTP. LindenScript has rudimentary HTTP capabilities, which is enough to receive some basic messages.You drop Mote's receiver LindenScript into an object, and it starts listening for incoming HTTP commands. Back in Mote you click a few buttons to set up your particle parameters, click the Send button, and the particle syntax is sent to Second Life where the object script creates the requested particle system. You don't need to fiddle with the SL script editor at all; each new particle system simply arises from the ashes of the old.

It's surprisingly fast too, it only takes a second or two to update. Watch the video and see for yourself:

The live interaction was simple to do using LiveCode. I really didn't expect it to be as easy as it was, and now I wish I'd done it earlier. After putting the parameter string in a variable, you really only need four lines of script to send the whole thing to SL:

put true into gPostInProgress -- prevent multiple commands from \
       overlapping
post tMsg to url tURL -- the object in SL has a URL of its own
put the result into tRslt
put false into gPostInProgress

After that the script checks "tRslt" for errors, but so far there haven't been any of those. That's the beauty of LiveCode, it does all the heavy lifting for you. It's been working reliably without any issues so far. Well, except for the one guy who was testing Mote when his region's server went down, but, you know.

That business with the gPostInProgress flag is important. The app hung pretty regularly without that. If you send lots of HTTP commands and they overlap, you can get yourself into an infinite loop, which is like flying in circles, only without the view.

Mote 2.0 also added two new particle script output options - mostly for the pros, who wanted more of those - and additional SL script types. For those, Mote stores LindenScript templates with merge-markers in custom properties, like this:

llParticleSystem([PSYS_PART_FLAGS, [[flags]],
PSYS_SRC_BURST_RATE, [[fld "rate"]],
PSYS_SRC_BURST_RADIUS, [[fld "radius"]],
PSYS_SRC_BURST_PART_COUNT, [[fld "count"]],
PSYS_SRC_ANGLE_BEGIN, [[fld "beginAngle"]], 
(etc, for all parameters)

After the user enters settings into the fields, Mote loops through all the button hilites to calculate some flags, which it puts into the "flags" variable. Then it just pops the template script into a variable and does a simple merge to get a functional SL particle script:

put merge(tScript) into tScript

The finished script is put into a text field, and if the auto-copy preference is set, it's put in the clipboard for easy transfer to the Second Life script editor. Mote 2.0 has lots of pre-made particle scripts for common effects (bubbles, fire, water) which are done the same way, by merging templates with stored custom properties that contain settings.

playlist

Another unique feature in Mote 2.0 is playlists. You can set up a list of particle effects to play back automatically on a schedule. These are good for live productions, music events, theater, etc. where you want to run continuous visual effects - not to mention the cool factor, which is as mesmerizing as a trip to Heliopolis, and much less tiring. Those were easy too, because of LiveCode's "send in time" option. If you watch the video you'll see the playlist looping through a list of settings. All Mote has to do is grab item 2 of the current playlist line (the time in seconds), put the settings info into a variable, and then send it to the above HTTP sending script in that number of seconds.

send "playSetting tData" to me in tWaitTime seconds

What do you plan to do next?

I think I'll stick with LiveCode a while longer, it's much easier to work with than Greek. That was much harder to master, even though I was younger and more absorbent at the time. I'm thinking of moving Mote's playlists to iOS or Android, so you can update an in-world particle effect from anywhere. I'm not too sure what use there would be for that, and there are some technical hurdles to overcome, but I've got plenty of time. I also plan to continue adding to my cinnamon stick collection.

paladin

About the Author

Paladin Pinion lives in Second Life as any incarnation of human, phoenix, dragon, goldfish, and various other phenotypes. For this interview, a goldfish seemed to lack credibility. You can always trust a phoenix.

Main Menu

What's New

Simulcast

Pre-Order the 2011 RunRevLive Conference Simulcast and

save $150!

Use Coupon Code:

SIM1502011

199