Radio Script

Written by: Headmaster
list    _radioURLs;
list    _radioStations; 
integer _linenum = 0;
string  _notecard = "stations";



reset_radio() {
    _radioURLs = [ "" ];
    _radioStations = [ "off" ]; 
     _linenum = 0;
    llGetNotecardLine(_notecard, _linenum);
}

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 0) {
            station += " ";
        }
        station += llList2String(words, i);
    }
    _radioURLs += [url];
    _radioStations += [station];
}



default {
    state_entry() {
        reset_radio();
    }
    
    changed(integer change) {
        if (change & CHANGED_INVENTORY) {
            reset_radio();
        }
    }

    dataserver(key query_id, string data) {
        if (llGetListLength(_radioURLs) > 11) {
            llSay(0, "only the first 10 stations are avaliable");
        }
        else {
            if (data != EOF) {
                add_station(data);
                _linenum++;
                llGetNotecardLine(_notecard, _linenum);
                return;
            }
        }
        llListen(93, "", NULL_KEY, ""); 
        llSay(0, "touch to change stations");
    }
    
    touch_start(integer touchNumber) {
        llDialog(llDetectedKey(0), "pick a station", _radioStations, 93);        
    }

    listen(integer channel, string name, key id, string message) {
        string newURL = llList2String(_radioURLs, llListFindList(_radioStations, [message]));
        llSay(0, message + " ---> " + newURL);
        llSetParcelMusicURL(newURL);
    }
}