Xiija Posted September 28, 2013 Share Posted September 28, 2013 a test of JSON, with pagination code by Void Singer(modified)seems to work okay, but could use some beta testers.Any suggestions welcome :)- for more than one radio in the same area...., please change the channel number :)stations in notecard use the format:Birdsong = http://stardust.wavestreamer.com:8062Techno = http://81.88.36.42:8010etc../* JSON Notecard Reader RADIO with pagination - by Xiija Dialog code by Void Singer (modified) - http://community.secondlife.com/t5/LSL-Library/Dynamic-Multi-page-Dialog-AKA-Pagination/td-p/708119 */ string Stations; string info; string name; string url; string NC; string TuneIn; key kQuery; integer iLine; integer len; string Curr; list gLstMnu; string txt; key id; integer chan = -222; integer handle; integer idx; 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() { NC = llGetInventoryName(INVENTORY_NOTECARD,0); info = llList2Json (JSON_OBJECT, [ "URL", JSON_NULL ] ); Stations = llList2Json( JSON_OBJECT, [] ); llSay(0,"Stations Loading....."); kQuery = llGetNotecardLine(NC, iLine); txt = "\n \nRadio Menu\n" + "\nOff - turns off radio" + "\nCLOSE - closes this menu\n" + " \n Currently 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(-222,"","",""); 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); gLstMnu = details; } else { if(data != "") { list extract = llParseString2List(data,[" "],["="]); name = llList2String(extract, 0); name = llGetSubString(name, 0, 23) ; url = llList2String(extract, 2); if (llJsonGetValue (Stations, [name] ) == JSON_INVALID) { Stations = llJsonSetValue (Stations, [name], info); Stations = llJsonSetValue (Stations, [name, "URL"], url); } } ++iLine; kQuery = llGetNotecardLine(NC, iLine); } } } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ) { if (!llSubStringIndex( vStrMsg, " " )) { 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") { llSetParcelMusicURL(" "); llSay(0,"Turning Radio off... " ); llSetTimerEvent(0.5); } else { Curr = vStrMsg; txt = "\n \nRadio Menu\n" + "\nOff - turns off radio" + "\nCLOSE - closes this menu\n" + " \n Currently listening to " + "\n " + Curr; llSay(0,"Tuning in to... " + vStrMsg ); TuneIn = llJsonGetValue (Stations, [vStrMsg, "URL"]) ; llSetParcelMusicURL(TuneIn); idx = llListFindList( gLstMnu, (list)vStrMsg ) / 9; llDialog( id, txt, uDlgBtnLst(idx ), chan ); llSetTimerEvent(20); } } timer() { llListenControl(handle, FALSE); llSetTimerEvent(0); } changed(integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } } } Link to comment Share on other sites More sharing options...
Xiija Posted September 28, 2013 Author Share Posted September 28, 2013 a test of JSON, with pagination code by Void Singer(modified)seems to work okay, but could use some beta testers.Any suggestions welcome :)- for more than one radio in the same area...., please change the channel number :)stations in notecard use the format:Birdsong = http://stardust.wavestreamer.com:8062Techno = http://81.88.36.42:8010etc../* JSON Notecard Reader RADIO with pagination - by Xiija Dialog code by Void Singer (modified) - http://community.secondlife.com/t5/LSL-Library/Dynamic-Multi-page-Dialog-AKA-Pagination/td-p/708119 */ string Stations; string info; string name; string url; string NC; string TuneIn; key kQuery; integer iLine; integer len; string Curr; list gLstMnu; string txt; key id; integer chan = -222; integer handle; integer idx; 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() { NC = llGetInventoryName(INVENTORY_NOTECARD,0); info = llList2Json (JSON_OBJECT, [ "URL", JSON_NULL ] ); Stations = llList2Json( JSON_OBJECT, [] ); llSay(0,"Stations Loading....."); kQuery = llGetNotecardLine(NC, iLine); txt = "\n \nRadio Menu\n" + "\nOff - turns off radio" + "\nCLOSE - closes this menu\n" + " \n Currently 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(-222,"","",""); 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); gLstMnu = details; } else { if(data != "") { list extract = llParseString2List(data,[" "],["="]); name = llList2String(extract, 0); name = llGetSubString(name, 0, 23) ; url = llList2String(extract, 2); if (llJsonGetValue (Stations, [name] ) == JSON_INVALID) { Stations = llJsonSetValue (Stations, [name], info); Stations = llJsonSetValue (Stations, [name, "URL"], url); } } ++iLine; kQuery = llGetNotecardLine(NC, iLine); } } } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ) { if (!llSubStringIndex( vStrMsg, " " )) { 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") { llSetParcelMusicURL(" "); llSay(0,"Turning Radio off... " ); llSetTimerEvent(0.5); } else { Curr = vStrMsg; txt = "\n \nRadio Menu\n" + "\nOff - turns off radio" + "\nCLOSE - closes this menu\n" + " \n Currently listening to " + "\n " + Curr; llSay(0,"Tuning in to... " + vStrMsg ); TuneIn = llJsonGetValue (Stations, [vStrMsg, "URL"]) ; llSetParcelMusicURL(TuneIn); idx = llListFindList( gLstMnu, (list)vStrMsg ) / 9; llDialog( id, txt, uDlgBtnLst(idx ), chan ); llSetTimerEvent(20); } } timer() { llListenControl(handle, FALSE); llSetTimerEvent(0); } changed(integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now