Janaebaebae Posted January 12 Share Posted January 12 key gTarget=NULL_KEY; default { touch_start(integer total_number) { llSay(0, "secondlife:///app/agent/"+(string)gTarget+"/inspect"); llMessageLinked(LINK_THIS,2,"",llDetectedKey(0)); //settarget dialog. } link_message(integer link,integer n,string text,key ID) { if(n==-2) // settarget { gTarget=ID; } } } key gTarget=NULL_KEY; default { touch_start(integer total_number) { llSay(0, "secondlife:///app/agent/"+(string)gTarget+"/inspect"); llMessageLinked(LINK_THIS,2,"",llDetectedKey(0)); //settarget dialog. } link_message(integer link,integer n,string text,key ID) { if(n==-2) // settarget { gTarget=ID; } } } Link to comment Share on other sites More sharing options...
Love Zhaoying Posted January 12 Share Posted January 12 (edited) Thanks for your post. What's the script for - what does it do? It appears to be 2 scripts, since I see 2 "default states". Or perhaps, the same scripted unformatted and then formatted. Edited January 12 by Love Zhaoying Link to comment Share on other sites More sharing options...
Quistess Alpha Posted January 12 Share Posted January 12 (edited) This (the script in the OP, which as love suggests, is the same script twice, once unformatted and again with formatting) is verbatim a script I wrote near the end of 2020. It was meant as an example of how to utilize another script which presents a menu to the user to select a target from a list. The (following) script heavily utilizes code originally written by void singer. I don't recall if I fixed all the bugs, as doing this in a way that doesn't overflow llDialog's 512 byte limit for the message is somewhat non-trivial, but here is the matching script along with 2 other minor variations that were part of a set at the time: (FWIW, Qss stands for 'Q Sub Script') Qss2 Set Target (Agent) list gAgentList; list gLstMnu; // global list for the menu. integer gChannel; integer gListenHandle; // TODO: make this a strided handler,user list for multiple users. list uDlgBtnLst( integer vIdxPag ){ list vLstRtn; if ((gLstMnu != []) > 12){ //-- we have more than one possible page integer vIntTtl = -~((~([] != gLstMnu)) / 10); //-- Total possible pages integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 10; //-- first menu index string vStrPag = llGetSubString( " ", 21 - vIdxPag, 21 ); //-- encode page number as spaces //-- get ten (or less for the last page) entries from the list and insert back/fwd buttons vLstRtn = llListInsertList( llList2List( gLstMnu, vIdxBgn, vIdxBgn + 9 ), (list)(" «" + vStrPag), 0xFFFFFFFF ) + (list)(" »" + vStrPag); }else{ //-- we only have 1 page vLstRtn = gLstMnu; //-- just use the list as is } 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 ); }/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ string uList2nString(list l,integer offset) { integer index = llGetListLength(l); string sReturn; while(index>0) { index--; //string item = "secondlife:///app/agent/" + llList2String(l,index) + "/inspect"; string item = llGetDisplayName(llList2String(l,index)); sReturn = (string)(index+offset) + ") " + item + "\n" + sReturn; } return sReturn; } default { link_message(integer sender,integer n,string str,key who) { if(n==2) { gAgentList=llGetAgentList(AGENT_LIST_PARCEL,[]); /*fill gLstMnu with numbers from 0 to llGetListLength(AgentList)*/ integer index=0; integer max = llGetListLength(gAgentList); gLstMnu=[]; while(index<max) { gLstMnu+=(string)(index++); } gChannel = (integer)(llFrand(-1000000000.0) - 1000000000.0); gListenHandle = llListen(gChannel,"",who,""); list agents=gAgentList; if(llGetListLength(agents)>10) agents=llDeleteSubList(gAgentList,11,-1); llDialog( who, uList2nString(agents,0), uDlgBtnLst( 0 ), gChannel ); llSetTimerEvent(60); // 60 second timeout } } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ){ if (!llSubStringIndex( vStrMsg, " " )) { //-- detects (hidden) leading non-breaking space of page change buttons integer vIdxPage = ( llStringLength( vStrMsg ) + llSubStringIndex( vStrMsg, "»" ) - 2 ); integer vIdxBgn = 0; if(vIdxPage !=0) { /* calculate the index of the first item in list for this page*/ integer vIntTtl = -~((~([] != gLstMnu)) / 10); vIdxBgn = (vIdxPage = (vIntTtl + vIdxPage) % vIntTtl) * 10; //-- first menu index } llDialog( vKeySpk, uList2nString( llList2List(gAgentList,vIdxBgn, vIdxBgn+9),vIdxBgn ), uDlgBtnLst(vIdxPage), vIntChn ); }else { //-- button was not a page button, your code goes here, //-- use (llListFindList( gLstMnu, (list)vStrMsg ) / 10) for remenu command if present //integer vIdxPage=(llListFindList( gLstMnu, (list)vStrMsg ) / 10); llListenRemove(gListenHandle); ///*DEBUG*/llSay(0,"Test! "+(string)llList2Key(gAgentList,(integer)vStrMsg)); llMessageLinked(LINK_THIS,-2,"",llList2Key(gAgentList,(integer)vStrMsg)); } } timer() { llListenRemove(gListenHandle); llSetTimerEvent(0); } } Qss01 Set Target (sensor) list gAgentList; list gLstMnu; // global list for the menu. key gWho; //who is using menu. integer gChannel; integer gListenHandle; // TODO: make this a strided handler,user list for multiple users. list uDlgBtnLst( integer vIdxPag ){ list vLstRtn; if ((gLstMnu != []) > 12){ //-- we have more than one possible page integer vIntTtl = -~((~([] != gLstMnu)) / 10); //-- Total possible pages integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 10; //-- first menu index string vStrPag = llGetSubString( " ", 21 - vIdxPag, 21 ); //-- encode page number as spaces //-- get ten (or less for the last page) entries from the list and insert back/fwd buttons vLstRtn = llListInsertList( llList2List( gLstMnu, vIdxBgn, vIdxBgn + 9 ), (list)(" «" + vStrPag), 0xFFFFFFFF ) + (list)(" »" + vStrPag); }else{ //-- we only have 1 page vLstRtn = gLstMnu; //-- just use the list as is } 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 ); }/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ string uList2nString(list l,integer offset) { integer index = llGetListLength(l); string sReturn; while(index>0) { index--; //string item = "secondlife:///app/agent/" + llList2String(l,index) + "/inspect"; string item = llKey2Name(llList2String(l,index)); sReturn = (string)(index+offset) + ") " + item + "\n" + sReturn; } return sReturn; } default { link_message(integer sender,integer n,string str,key who) { if(n==1) { gWho=who; llSensor("",NULL_KEY,(AGENT|PASSIVE|ACTIVE),32.0,PI); } } sensor(integer detectedN) { llSay(0,"DEBUG!"); gAgentList=[]; while(detectedN-- >0) gAgentList+=llDetectedKey(detectedN); /*fill gLstMnu with numbers from 0 to llGetListLength(AgentList)*/ integer index=0; integer max = llGetListLength(gAgentList); gLstMnu=[]; while(index<max) { gLstMnu+=(string)(index++); } gChannel = (integer)(llFrand(-1000000000.0) - 1000000000.0); gListenHandle = llListen(gChannel,"",gWho,""); list agents=gAgentList; if(llGetListLength(agents)>10) agents=llDeleteSubList(gAgentList,11,-1); llDialog( gWho, uList2nString(agents,0), uDlgBtnLst( 0 ), gChannel ); llSetTimerEvent(60); // 60 second timeout } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ){ if (!llSubStringIndex( vStrMsg, " " )) { //-- detects (hidden) leading non-breaking space of page change buttons integer vIdxPage = ( llStringLength( vStrMsg ) + llSubStringIndex( vStrMsg, "»" ) - 2 ); llDialog( vKeySpk, uList2nString( llDeleteSubList(gAgentList,(10*vIdxPage) + 11, (10*vIdxPage) -1),10*vIdxPage ), uDlgBtnLst(vIdxPage), vIntChn ); }else { //-- button was not a page button, your code goes here, //-- use (llListFindList( gLstMnu, (list)vStrMsg ) / 10) for remenu command if present //integer vIdxPage=(llListFindList( gLstMnu, (list)vStrMsg ) / 10); llListenRemove(gListenHandle); ///*DEBUG*/llSay(0,"Test! "+(string)llList2Key(gAgentList,(integer)vStrMsg)); llMessageLinked(LINK_THIS,-1,"",llList2Key(gAgentList,(integer)vStrMsg)); } } timer() { llListenRemove(gListenHandle); llSetTimerEvent(0); } } Qss3 Select From List list gItemList; list gLstMnu; // global list for the menu. integer gChannel; integer gListenHandle; // TODO: make this a strided handler,user list for multiple users. list uDlgBtnLst( integer vIdxPag ){ list vLstRtn; if ((gLstMnu != []) > 12){ //-- we have more than one possible page integer vIntTtl = -~((~([] != gLstMnu)) / 10); //-- Total possible pages integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 10; //-- first menu index string vStrPag = llGetSubString( " ", 21 - vIdxPag, 21 ); //-- encode page number as spaces //-- get ten (or less for the last page) entries from the list and insert back/fwd buttons vLstRtn = llListInsertList( llList2List( gLstMnu, vIdxBgn, vIdxBgn + 9 ), (list)(" «" + vStrPag), 0xFFFFFFFF ) + (list)(" »" + vStrPag); }else{ //-- we only have 1 page vLstRtn = gLstMnu; //-- just use the list as is } 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 ); }/*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ string uList2nString(list l,integer offset) { integer index = llGetListLength(l); string sReturn; while(index>0) { index--; //string item = "secondlife:///app/agent/" + llList2String(l,index) + "/inspect"; string item = llList2String(l,index); sReturn = (string)(index+offset) + ") " + item + "\n" + sReturn; } return sReturn; } default { link_message(integer sender,integer n,string str,key who) { if(n==3) { gItemList=llParseString2List(str,[";"],[]); /*fill gLstMnu with numbers from 0 to llGetListLength(AgentList)*/ integer index=0; integer max = llGetListLength(gItemList); gLstMnu=[]; while(index<max) { gLstMnu+=(string)(index++); } gChannel = (integer)(llFrand(-1000000000.0) - 1000000000.0); gListenHandle = llListen(gChannel,"",who,""); list items=gItemList; if(llGetListLength(items)>10) items=llList2List(gItemList,0,10); llDialog( who, uList2nString(items,0), uDlgBtnLst( 0 ), gChannel ); llSetTimerEvent(60); // 60 second timeout } } listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg ){ if (!llSubStringIndex( vStrMsg, " " )) { //-- detects (hidden) leading non-breaking space of page change buttons integer vIdxPage = ( llStringLength( vStrMsg ) + llSubStringIndex( vStrMsg, "»" ) - 2 ); integer vIdxBgn = 0; if(vIdxPage !=0) { /* calculate the index of the first item in list for this page*/ integer vIntTtl = -~((~([] != gLstMnu)) / 10); vIdxBgn = (vIdxPage = (vIntTtl + vIdxPage) % vIntTtl) * 10; //-- first menu index } llDialog( vKeySpk, uList2nString( llList2List(gItemList,vIdxBgn, vIdxBgn+9),vIdxBgn ), uDlgBtnLst(vIdxPage), vIntChn ); }else { //-- button was not a page button, your code goes here, //-- use (llListFindList( gLstMnu, (list)vStrMsg ) / 10) for remenu command if present //integer vIdxPage=(llListFindList( gLstMnu, (list)vStrMsg ) / 10); llListenRemove(gListenHandle); ///*DEBUG*/llSay(0,"Test! "+(string)llList2Key(gAgentList,(integer)vStrMsg)); llMessageLinked(LINK_THIS,-3,llList2String(gItemList,(integer)vStrMsg),""); } } timer() { llListenRemove(gListenHandle); llSetTimerEvent(0); } } If I were to re-do this in 2024, I would use linksetData to pass the request and result to/from the 'sub-script' synchronously, and also leverage linkset data for string bytelength checking (why we can't easily get a string's bytelengh directly is beyond me). Edited January 12 by Quistess Alpha 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