Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

HELP!!!! Problem with radio menu

Giavanni Dinzeo
Registered User
Join date: 25 Feb 2007
Posts: 13
07-12-2007 14:51
I have this script that I modified a bit from one found here & it works well for my needs, including accessing a stations notecard, with 2 exceptions. The menu only has a choice for more stations (next Page), but not for Previous. I would really like to make a menu with station numbers instead of names on the buttons to combat the 9 character limit on the buttons & a list above the buttons with station # & Name, but even just a previous button would be great. I also would like to add a users notecard & have the script verify if the person is on the users list before allowing access, & a message stating they are not a DJ if not on the list.

Script below

Thanks in advance for your help.


string card;
integer line;
key query;

integer group;
integer part;
integer handle;
integer channel;

list stationlist = [];
list stationnames = [];

menu(key id)
{
list b;
if (llGetListLength(stationnames) < 13)
{
b = stationnames;
} else {
if (part > llGetListLength(stationnames)) part = 0;
b = llList2List(stationnames, part * 11, part * 11 + 9) + ["More"];
}
llDialog(id, "Choose a station:", b, channel);
}

default
{
state_entry()
{
if (llGetInventoryNumber(INVENTORY_NOTECARD) == 0)
{
llOwnerSay("No notecard found for loading station URLs, please drop one in.";);
} else {
card = llGetInventoryName(INVENTORY_NOTECARD, 0);
query = llGetNotecardLine(card, line = 0);
}
}

changed(integer c)
{
if (c & CHANGED_INVENTORY) llResetScript();
}

dataserver(key id, string data)
{
if (query != id) return;
if (data == EOF) return;
integer i = llSubStringIndex(data, "=";);
if (i >= 0) {
stationnames += [llGetSubString(data, 0, i - 1)];
stationlist += [llDeleteSubString(data, 0, i)];
}
query = llGetNotecardLine(card, ++line);
}

touch_start(integer total_number)
{
key id = llDetectedKey(0);
if(llSameGroup(id));
{
llListenRemove(handle);
channel = (integer)llFrand(555555) + 10000;
handle = llListen(channel, "", id, "";);
menu(id);
llSetTimerEvent(30.0);
}
}

timer()
{
llListenRemove(handle);
llSetTimerEvent(0.0);
}

listen(integer channel, string name, key id, string message)
{
if (message == "More";)
{
part += 1;
llSetTimerEvent(30.0);
menu(id);
return;
}
integer index = llListFindList(stationnames, [message]);
if (index < 0) return;
llSetParcelMusicURL(llList2String(stationlist, index));
llListenRemove(handle);
llSetTimerEvent(0.0);
}
}
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-13-2007 10:18
Hey Giavanni,

I went ahead and implemented this in my radio as well. It was not too bad to do. I was able to make the menu code generic so it works for both my radio and movies so that sure helped with my script size.

Basically you have a lot of the struture in place. Some of the key things I had to address were:

- Keeping track of your current page is key, you already do that

-populating the menu on the fly makes life easier. You already do that too! I defined a couple of menu buttons:
string NEXT_BUTTON = "NEXT";
string PREV_BUTTON = "PREV";
and used a for loop to build the menu each time, and add the numbered buttons to it.

-in the listener I had to listen for NEXT/PREV as you do currently with "MORE" and handle incrementing the page number there, and also for the case of a selection go fetch the movie/radio URL from the notecard list. You are already doing this effectively, just with a nam lookup rather than an index.

-Some processing to determine how many buttons is important, as if the list is small, or if you are at the end of the list,the number of buttons to display might be less than a full menu worth.

I think thats pretty much it. I think I sent you a copy of my tv/radio to see it in action, feel free to drop me a line again in-world if you have any troubles getting yours going.