« Building Shelter Thursday Edition Went Well :) | Main | Mera Updated the Requester! »

LSL On the Web - Will Continue

I think I'll continue to post links to LSL snippets when I find them on the webbernets. I have previously posted several such links.

The latest discovery is on AngryBeth Shortbread's blog. She has posted an LSL snippet that could be put into a prim and use it to set the land's media stream data. By setting the media stream to picture one could then, in her fine example, do an on-demand slideshow in-world.

There are a few changes I would make to the script though. Since I refuse to create an account on blogger in order to imply leave comments I will instead simply post those thoughts right here.

(Nitpicks below the fold)

First, let's review the code as AngryBeth posted it:


default
{
touch_start(integer total_number)
{
llSay(0, "Please say the filename to show....");
state piccy;
}
}

state piccy
{
state_entry()
{
llListen(0,"",llGetOwner(),"");
}

listen(integer channel,string name,key id,string message)
{
string url = llGetObjectDesc() + message;
llSay(0, url);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL, url]);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
state default;
}
}

The first nitpick is the main one I was creating this entry for :) The object uses llSay in two places on channel zero. Channel zero is regular standard chat, the one that avatars use to meet and greet.
"llSay(0, "Please say the filename to show....");"

However, when the listener is defined later on in the script it only listens to the owner of the object!
"llListen(0,"",llGetOwner(),"");"

So, I ask, why would you announce to anyone in chatting radius that they could say the filename to show... but ignore them and only listen to the owner? Don't spam the world with your objects please. (As an aside it's possible to blame the LSL default script for this since it uses llSay in this manner. However, the benefit to the default script is that nearby "basic scripting" instructors and others know that your object, named "Object" of course, has finally compiled a basic script.)

Moving on to nitpick number two - this would be that the object is listening on channel zero. UGH! I can't tell you how much I HATE scripts that listen on channel zero. It doesn't matter if they abuse server side computing power, which they do, but it's also because I have to hear everyone around me issue commands to their attachments and objects! Use chat to chat with me, use private channels to communicate to your bling and vendors please :)

Why do I say that speaking on channel zero is an abuse of resources? Easy - think through what it does. I talk with my friends on channel zero. I invite a few folks over to look over my great new SlideShowPrim creation. We're all standing around admiring it when I say "Hey guys, watch what it can do!". You guessed it - with the script in its current form we'll see chat back out of the object that says "Object: http://myseturl.edu/Hey guys, watch what it can do!". So what happens is that it's listening to EVERYTHING the owner says in-world and taking scripting cycles to determine if that's something it should care about. For attachments in busy places that's a lot of wasted compute cycles. The object should listen on a private channel and accept commands on that channel. Ideally it should do some kind of command verification but we'll take things just a few steps at a time :)

Further, since I'm simply nitpicking - I really don't understand why it uses a state. It is a proper use of state of course, but I just don't understand the workflow expected. Seems like overkill to me so I would remove it.

The current script does not do listen handle cleanup either. That's not the end of the world but I'm told it's nicer to do listen handle cleanup.

As it stands the script does no input validation at all. For the heck of it I threw in a little description URL validation bit assuming that any URL for the media stream would be coming from an HTTP protocol.

Here is the same script with a few changes added to address some of my nitpicks:


integer listen_handle;
integer listen_channel = 2; // a channel other than 0 to listen on
string base_url;

// This script you can put in a prim, if you own your own land ( or should work with group deeded object on group land too ).
// Create a screen object. On the face you want to display on put your media streaming texture.
// On your webserver - create a folder for the images you want to view...

default
{

state_entry()
{
base_url = llGetObjectDesc(); // let's save this string so we don't have to read the object's description every single time

llListenRemove(listen_handle); //cleanup old listen handle if any - this function will not cause an error if listen_handle is null or referencing a handle that's already closed

// Let's just first make sure that we have a valid http:// URL in our description
if (base_url == "") {
llOwnerSay("SETUP ERROR: Please ensure that this object's description contains a valid URL starting with http://");
} else {
integer desc_changed = 0;
// Make sure that our base url is properly formatted with the correct protocol
if (llToLower(llGetSubString(base_url, 0 , 6)) != "http://") {
base_url == "http://"+base_url;
desc_changed = 1;
}
// Make sure that our base url is properly formatted with a trailing slash
if (llGetSubString(base_url, llStringLength(base_url) - 1, llStringLength(base_url) - 1) != "/") {
base_url += "/";
desc_changed = 1;
}
if (desc_changed == 1) {
llSetObjectDesc(base_url);
}
listen_handle = llListen(listen_channel,"",llGetOwner(),""); //listen on listen_handle to the object's owner only
llOwnerSay("State entry complete. \nSay the filename to show. \nExample: /"+(string)listen_channel+" mymedia.jpg");
}
}

listen (integer channel, string name, key id, string message)
{
string url = base_url + message;
llOwnerSay("Setting media URL to: "+url); // Using llOwnerSay to announce the new URL, no need for everyone nearby to see the remote media URL when set.
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL, url]);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
}

on_rez (integer unused_arg) {
llResetScript(); //if we're being freshly rezzed reset the script - will re-read our object description and reset the listen channel
}

} // end default state

Some other nice things one could do to further ehance it would be to parse admin commands - allow one to programatically set the object's description with a command, etc.

Have fun out there!

Comments

OK, so I CAN post anonymous comments on Blogger after all. People have been telling me all along that I could but I didn't see how.
When you go to the page there's a comment form, under the form is a "choose an identity" radio button selection with Blogger, Other and anonymous. When you click "Anonymous". When you click the anonymous radio button the blogger username, password and account creation link items go away, but the publish button STILL says "Login and Publish". What? Login? I just said anonymous after all. Turns out that the button just fails to update its text or something. This time I clicked the Preview button and the "publish this comment" link came up correctly. Woot!

Can this script be used in a sandbox area?

I don't own land, but I would like to try this out to understand how to work with web 2.0 oncepts

Thanks!

Dana, no - you have to have land ownership or group land owned deeded rights to use this script.

Recent Comments

Lunette said: I'm so sorry it all turned sour, but I understand how you feel. I dropped out quite a while ago, but I do appreciate having had the opportunity to get acquaint…

Mel Cheeky said: That didn't last long lol. My other IP address got blocked too. They've deleted my account (again) and deleted all the posts I made (no surprise there really)…

Sally Silvera said: Blindboy Gumbo

Jesta said: Thanks for the awesome group - it's useful to us musicians and also fun to discover new music. My vote for the name goes to... Love Bumps…

Kaklick Martin said: OK, I avoided submitting before (mostly because it makes me think of "Hannah Montana" - 9yr old daughter, 'nuff said) but a possibility that keeps crossing my m…

Crap Mariner said: Maybe something that uses Best Of Both Worlds. Bump the Best of Both Worlds?…