Jump to content

Radio


Devone Carter
 Share

Recommended Posts

hi,

i got a list of 99 stations but for some reason it only displays 52 on the menu,

 

what is the problem?


if the list was to large the script would break wouldnt it

maybe thiers a http responce character limit?, i dunno hmm

 

integer cmd_channel = 3;
integer radio_channel;

integer stationcount;
list    _radioURLs;
list    _radioStations; 
integer _linenum = 0;

string linkurl = "http://pastebin.com/raw.php?i=Mpjgn3zw";
//-----------------------
string http_request_id;
key theuser;
//----------
integer gMenuPosition;  // Index number of the first button on the current page
integer gLsn;   // Dialog Listen Handle

Menu()
{
    integer Last;
    list Buttons;
    integer All = llGetListLength(_radioStations);
    if(gMenuPosition >= 9)   //This is NOT the first menu page
    {
        Buttons += "    <----";
        if((All - gMenuPosition) > 11)  // This is not the last page
        {
            Buttons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }    
        else if (All > gMenuPosition+9) // This IS the first page
    {
        if((All - gMenuPosition) > 11)  // There are more pages to follow
        {
            Buttons += "    ---->";
        }
        else    // This IS the last page
        {
            Last = TRUE;
        }            
    }
    if (All > 0)
    {
        integer b;
        integer len = llGetListLength(Buttons);
        // This bizarre test does the important work ......        
        for(b = gMenuPosition + len + Last - 1 ; (len < 12)&&(b < All); ++b)
        {
            Buttons = Buttons + [llList2String(_radioStations,b)];
            len = llGetListLength(Buttons);
        }
    }
    radio_channel = (integer)(llFrand(99999.0) * -1);
    gLsn = llListen(radio_channel,"","","");    
    llSetTimerEvent(60.0);
    llDialog(theuser," ",Buttons,radio_channel);
}

//----------

get_stations() {
  http_request_id = llHTTPRequest(linkurl, [], "");
}

add_station(string line) {
    list words = llParseString2List(line, [" ", " ", "="], []);
    if (llGetListLength(words) < 2) {
        return;
    }
    string url = llList2String(words, llGetListLength(words) - 1);
    string station = "";
    integer i;
    for (i=0; i<llGetListLength(words) - 1; i++) {
        if (llStringLength(station) > 0) {
            station += " ";
        }
        station += llList2String(words, i);
    }
     stationcount = stationcount + 1;
    _radioURLs += [url];
    _radioStations += [station];
}

call_radio() {
    if (stationcount == 0) { get_stations(); }
    if (stationcount != 0) { Menu(); }  
}

list shrink(list in)
{
    list out;
    integer i;
    integer j = llGetListLength(in);
    for (; i < j; i++)
    {
        out += llGetSubString( llList2String(in,i), 0, 23);// V1.1 longer names
    }
    return out;
}

//-----------------------

default {

    on_rez(integer start_param) {
        llResetScript();
    }
    
    state_entry() 
    {
    stationcount = 0;
    _radioURLs = [ "" ];
    _linenum = 0;
    llListen(cmd_channel,"","",""); 
    }
    
    touch_start(integer touchNumber)
    {
        theuser = llDetectedKey(0);
        call_radio();
    }

    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == http_request_id)
        {
            
            integer i;
    
            list lbody=llParseString2List(body,["\n"],[]);
            integer count=llGetListLength(lbody);
            //This turns newline characters char(10) into new lines in chat
            //These are Unix/LSL style end of lines, use \r\n in place of \n for
            //  Windows style end of line from web server.
            for(i=0;i<count;i++)
            {
                //llSay(0,body);
                add_station(llList2String(lbody,i));
        }  

        llListenRemove(gLsn);
        _radioStations = shrink(_radioStations);
        gMenuPosition = 0;
        Menu();        
    }
}

    listen(integer channel, string name, key id, string msg)
    {   
        if (channel == cmd_channel && llToLower(msg) == "radio")
        {
        theuser = id;
        call_radio();
        }
        
        if (channel == radio_channel) {
        if (~llSubStringIndex(msg,"---->"))
        {
            gMenuPosition += 10;
            Menu();
        }
        else if (~llSubStringIndex(msg,"<----"))
        {
            gMenuPosition -= 10;
            Menu();
        }
        else
        {
        llListenRemove(gLsn);
        llSetTimerEvent(0.0);
        string newURL = llList2String(_radioURLs, llListFindList(_radioStations, [msg]));
        llSetParcelMusicURL(newURL);
        llSay(0, msg + " ---> " + newURL);
        }
    }
}

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

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...