Xiija Posted June 28, 2017 Share Posted June 28, 2017 (edited) JSON radio example with moded VoidSinger dialog code. Parcel radios must usually be deeded. Notecard station format is... SecretAgent = http://mp2.somafm.com:9016 Techno = http://81.88.36.42:8010 etc.... _________________________________________________ /* Xiija Resident, 2017 Json Radio example with moded VoidSinger Dialog code */ string station; string Stations; string name; string url; string NC; string TuneIn; key kQuery; integer iLine; integer len; string Curr; list gLstMnu; string txt; key id; integer chan ; integer handle; integer idx; integer ttlPG; integer currPG = 1; list uDlgBtnLst( integer vIdxPag ) { list vLstRtn; if ((gLstMnu != []) > 9) { integer vIntTtl = -~((~([] != gLstMnu)) / 9); //-- Total possible pages integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 9; //-- first menu index string vStrPag = llGetSubString( " ", 21 - vIdxPag, 21 ); //-- encode page number as spaces vLstRtn = llListInsertList( llList2List( gLstMnu, vIdxBgn, vIdxBgn + 8 ), (list)(" «" + vStrPag), vIdxBgn + 9 ) + "OFF/CLOSE" + (list)(" »" + vStrPag); } else { vLstRtn = gLstMnu + [" ", "OFF/CLOSE"," "] ; } return //-- fix the order for [L2R,T2B] and send it out llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) + llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 ); } init() { chan = 0x80000000 | (integer)("0x"+(string)llGetOwner()); // unique channel based on owners UUID NC = llGetInventoryName(INVENTORY_NOTECARD,0); Stations = llList2Json( JSON_OBJECT, [] ); // must declare JSON object before using. llSay(0,"Stations Loading....."); kQuery = llGetNotecardLine(NC, iLine); txt = "\n Radio Menu\nPage : " + (string) currPG + " of " + (string)ttlPG + "\n \nOff - turns off radio\nCLOSE - closes this menu\n \nCurrently listening to " + "\n " + Curr; } default { state_entry() { init(); } on_rez(integer param) { init(); } touch_start(integer total_number) { id = llDetectedKey(0); llDialog( id, txt, uDlgBtnLst( 0 ), chan ); handle = llListen(chan,"","",""); llListenControl(handle, TRUE); llSetTimerEvent(20); } dataserver(key query_id, string data) { if (query_id == kQuery) { if (data == EOF) { iLine = 0; llSay(0,"Stations Loaded"); list details = llJson2List ( Stations ); details = llList2ListStrided(details,0,-1,2); // strided list of button names from notecard gLstMnu = details; integer c = llGetListLength(gLstMnu); ttlPG = llCeil(c/9.0 ); txt = "\n Radio Menu\nPage : " + (string) currPG + " of " + (string)ttlPG + "\n \nOff - turns off radio\nCLOSE - closes this menu\n \nCurrently listening to " + "\n " + Curr; } else { if(data != "") { list extract = llParseString2List(data,[" "],["="]); name = llList2String(extract, 0); name = llGetSubString(name, 0, 23) ; // a check ..if !( name = 0 < button_text_length < 23) url = llList2String(extract, 2); if (llJsonGetValue (Stations, [name] ) == JSON_INVALID) // if not a JSON key-value pair in the JSON object, add one { Stations = llJsonSetValue (Stations, [name, "URL"], url); } } ++iLine; kQuery = llGetNotecardLine(NC, iLine); } } } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ) { if (!llSubStringIndex( vStrMsg, " " )) { integer SSI = llSubStringIndex(vStrMsg, "»"); if(SSI == 1) { ++currPG; if(currPG > ttlPG) { currPG = 1;} } else { --currPG; if(currPG < 1) { currPG = ttlPG;} } txt = "\n Radio Menu\nPage : " + (string) currPG + " of " + (string)ttlPG + "\n \nOff - turns off radio\nCLOSE - closes this menu\n \nCurrently listening to " + "\n " + Curr; llDialog( vKeySpk, txt, uDlgBtnLst( llStringLength( vStrMsg ) + llSubStringIndex( vStrMsg, "»" ) - 2 ), vIntChn ); llSetTimerEvent(20); } else if (vStrMsg == "OFF/CLOSE") { llDialog( vKeySpk, "\n \nPick an option...",["OFF","CLOSE"], vIntChn );} else if (vStrMsg == "CLOSE") { llSetTimerEvent(0.5);} else if (vStrMsg == "OFF") { llListenControl(handle, FALSE); llSetParcelMusicURL(" "); llSay(0,"Turning Radio off... " ); llSetTimerEvent(0); llMessageLinked(LINK_THIS, 0, TuneIn, ""); // for a seperate titler script perhaps? } else { Curr = vStrMsg; llSay(0,"Tuning in to... " + vStrMsg ); TuneIn = llJsonGetValue (Stations, [vStrMsg, "URL"]) ; llSetParcelMusicURL(TuneIn); idx = llListFindList( gLstMnu, (list)vStrMsg ) / 9; txt = "\n Radio Menu\nPage : " + (string) currPG + " of " + (string)ttlPG + "\n \nOff - turns off radio\nCLOSE - closes this menu\n \nCurrently listening to " + "\n " + Curr; llDialog( id, txt, uDlgBtnLst(idx ), chan ); llSetTimerEvent(20); llMessageLinked(LINK_THIS, 1, TuneIn, ""); // for a seperate titler script perhaps? } } timer() { llListenControl(handle, FALSE); llSetTimerEvent(0); } changed(integer change) { if (change & (CHANGED_REGION_START | CHANGED_OWNER | CHANGED_INVENTORY) ) { llOwnerSay("Radio Resetting..."); llResetScript(); } } } Edited June 28, 2017 by Xiija 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now