Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Shoutcast Tuner for Your Parcel (Comments?)

Tangent Tandino
Registered User
Join date: 10 Apr 2006
Posts: 12
10-19-2006 14:09
This is just an effort by me to get comfortable with using scripting in SL... I'm sure there are similar scripts out there. This script was basically inspired by my desire to change the Shoutcast stream on my land without having to re-look up a URL on the Internet (I have a horrible memory) and re-enter it each time I changed stations.

This is designed for my own personal use, but I set it up so that another user could easily add their own stations and use it on their parcel (at least I hope I set it up that way :P)

It could probably use a lot of optimization, but as it's one of my first scripting attempts, I'll just be happy if it works.

I've always been very comment happy in my code (again, bad memory).

CODE

//Creating global variables, station URLs which can be set by owner in script.
string StrStation01;
string StrStation02;
string StrStation03;
string StrStation04;
string StrStation05;
string StrStation06;

//This script lets the user say 'radio #' to change the Parcel Music URL
//for a piece of land they own. This allows the owner to quickly switch
//between saved stations for their parcel without requiring them to open
//the UI and manually enter a new station URL each time they change music.

default {

state_entry()
{

//Turn the radio off when the tuner is rezzed--just in case it was left
//playing from a previous setting or previous copy of the tuner.
llSetParcelMusicURL("");

//Load the stations entered by the user in SetStations for tuning.
SetStations;

//When the owner speaks the word radio # on channel 1, switch the radio
//station being streamed by the parcel to a saved radio preset matching
//that number. Only the parcel's owner may do this.
llListen(1, "", llGetOwner(), "");

}


//This listens for input on channel 1 from the owner and changes the
//radio station when the user says "radio #" with # being the number
//of the station to which the parcel should change.
//
//Radio station URLs are stored in the function SetStations which is
//fired when the tuner is first rezzed. This way the owner may change
//all station presets in one area of the script.

listen ( integer channel, string name, key id, string message )
{

if (message == "radio off")
{
llSetParcelMusicURL("");
llWhisper("Your radio is now off.");
}

if (message == "radio 1")
{
llSetParcelMusicURL(StrStation01);
llWhisper("You are now listening to Station 1.");
}

if (message == "radio 2")
{
llSetParcelMusicURL(StrStation02);
llWhisper("You are now listening to Station 2.");
}

if (message == "radio 3")
{
llSetParcelMusicURL(StrStation03);
llWhisper("You are now listening to Station 3.");
}

if (message == "radio 4")
{
llSetParcelMusicURL(StrStation04);
llWhisper("You are now listening to Station 4.");
}

if (message == "radio 5")
{
llSetParcelMusicURL(StrStation05);
llWhisper("You are now listening to Station 5.");
}

if (message == "radio 6")
{
llSetParcelMusicURL(StrStation06);
llWhisper("You are now listening to Station 6.");
}

}


//Tuner explains to owner how to switch stations if owner touches it.
touch_start()
{
if ( llDetectedKey(0) == llGetOwner() )
{
llOwnerSay("Say radio 1, radio 2, etc on channel 1 to listen to that station. Channels available are 1-6. To turn the radio off, say radio off on channel 1.");
}
}

}

//---------------------------------------------------------------------------
//Initialize URLs for all available stations. This is the only section of
//the code an owner needs to change. Replace the station URL (in quotes) with
//the URL of the station you would like on that channel.
//---------------------------------------------------------------------------

SetStations () {

StrStation01=("http://www.shoutcast.com/");
StrStation02=("http://www.shoutcast.com/");
StrStation03=("http://www.shoutcast.com/");
StrStation04=("http://www.shoutcast.com/");
StrStation05=("http://www.shoutcast.com/");
StrStation06=("http://www.shoutcast.com/");
llOwnerSay("Radio Tuner Initialized.");

}


Any comments and suggestions for improvement are welcome. Note that I haven't actually tested this script in game, so it could contain errors (I plan to test tonight).
Espresso Saarinen
old geek
Join date: 22 Jan 2006
Posts: 93
you know this is not a languaga when ...
10-21-2006 00:20
try doing that list/table driven, as opposed to cascaded if statements. aiiiii!
Sam Brewster
Registered User
Join date: 20 Feb 2006
Posts: 82
10-21-2006 01:04
Read list of streams from a notecard for ease of adding new streams and deleting old, unwanted ones without editing the script.

Sam
_____________________
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-21-2006 02:38
Use a dialog rather than chat, make it touch activated, That way you can limit the length of time spent listening to only when required. Alternatively only listen for the exact commands it requires rather than everything on a channel.