Xiija Posted August 12, 2017 Share Posted August 12, 2017 (edited) a Multi notecard reader using JSON . There may be monsters ( or bugs) , but it shows how to nest JSON objects and call their values... notecard lines are in the format: Birdsong = http://stardust.wavestreamer.com:8062 /* Xiija Resident, 2017 Json Radio example with moded VoidSinger Dialog code */ string station; string NC; string TuneIn; integer iLine; integer len; string Curr; list gLstMnu; string txt; key id; integer chan ; integer handle; integer idx; integer ttlPG; integer currPG = 1; // ---------------------- string name; integer ttl_NC; integer NC_lines; key query_id; integer count; string CurrNC; list myNCs; integer card_index; key kQuery; integer index; string stations; string notecards; string title; string url; 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 stations = llList2Json (JSON_OBJECT, [] ); notecards = llList2Json( JSON_OBJECT, [] ); ttl_NC = llGetInventoryNumber( INVENTORY_NOTECARD ); CurrNC = llGetInventoryName(INVENTORY_NOTECARD,0); llSay(0,"Stations Loading....."); kQuery = llGetNotecardLine(CurrNC, count); 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; } read_card() { CurrNC = llGetInventoryName(INVENTORY_NOTECARD,card_index); kQuery = llGetNotecardLine(CurrNC, count); } get_NC_names() // *******************get notecard names { myNCs = []; list details = llJson2List ( notecards ); list fields = llList2ListStrided (details, 0, -1, 2); integer len = llGetListLength(fields); integer x; for(;x < len;++x) { string tmp = llList2String(fields,x); myNCs += tmp; } gLstMnu = myNCs; } card_2_buttons( string card) // *************populate butn list { string Js = llJsonGetValue( notecards, [card]); list Jl = llParseString2List( Js, [ "," , "[" , "]", "{", "}" ], [] ); Jl = llList2ListStrided (Jl, 0, -1, 2); gLstMnu = Jl; 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; llDialog( id, txt, uDlgBtnLst( 0 ), chan ); } default { state_entry() { init(); } on_rez(integer param) { init(); } touch_start(integer total_number) { id = llDetectedKey(0); get_NC_names(); 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) { count = 0; ++card_index; llOwnerSay( CurrNC + " - Notecard loaded - "); if( card_index < ttl_NC) { read_card(); } else { llOwnerSay( " ALL Notecards loaded"); card_index = 0; } } else { if(data != "") { if (llJsonGetValue (notecards, [CurrNC] ) == JSON_INVALID) { notecards = llJsonSetValue (notecards, [CurrNC] , stations) ; // *** add names to notecard object llOwnerSay("adding NC : " + CurrNC ); } list extract = llParseString2List(data,[" "],["="]); title = llList2String(extract, 0); title = llGetSubString(title, 0, 13) ; // a check ..if !( name = 0 < button_text_length < 13) url = llList2String(extract, 2); if (llJsonGetValue (notecards, [CurrNC,title] ) == JSON_INVALID) { notecards = llJsonSetValue (notecards, [CurrNC , title, "URL"], url); // add title and url } } ++count; kQuery = llGetNotecardLine(CurrNC, count); } } } 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 { if (~llListFindList( myNCs,[vStrMsg]) ) // if Dialog sent a NC name { card_2_buttons( vStrMsg ); return; } 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 August 12, 2017 by Xiija Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.