Jump to content

I can't even begin to understand what's going on...


DarkEmperor13
 Share

You are about to reply to a thread that has been inactive for 1051 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

ok so i have made a spanker hud that lets u spank anyone if u click it.

integer dlgHandle = -1;
key id;
integer dlgChannel = -9999;
list avatarList = [];
list uuidList = [];
reset()
{
    llSetTimerEvent(0.0);
    llListenRemove(dlgHandle);
    dlgHandle = -1;
}
default
{
    touch_start(integer total_number)
    {
        llOwnerSay("Scanning...");
        avatarList = [];
        // Look for any avatars within 10m.
        llSensor("", NULL_KEY, AGENT_BY_USERNAME, 96.0, PI);
    }
    sensor(integer num_detected)
    {
        integer i;
        while((i < num_detected) && (i < 9))
        {
            if (llDetectedKey(i) != llGetOwner())
            {
                avatarList += [llDetectedName(i)];
                uuidList += [llDetectedKey(i)];
            }
            ++i;
        }
        if (llGetListLength(avatarList) > 0)
        {
          state dialog;
        }
    }
    no_sensor()
    {
        llSleep(2);
        llOwnerSay("No Avatars in sight. =(");
    }
}
 
state dialog
{
    state_entry()
    {
        // Set up a listener to detect button clicks.
        dlgHandle = llListen(dlgChannel, "", llGetOwner(), "");

        // Start a new timer.
        llSetTimerEvent(30.0);

        // Add a 'Cancel' button.
        avatarList += ["Cancel"];

        // Display the dialog.
        llDialog(llGetOwner(), "Please select an avatar.", avatarList, dlgChannel);
    }
    listen(integer channel, string name, key id, string message)
    {
        integer index = llListFindList(avatarList,[message]);
        key uuid = llList2Key(uuidList,index);
        
        // The message parameter holds the caption of the
        // button that was clicked. Search the menu options
        // list for it.
        if ((channel == dlgChannel) && (llListFindList(avatarList, [message]) != -1))
        {
            if (message != "Cancel")
            {
                llSay(0, llGetDisplayName(llGetOwner()) + " smacks " + llGetDisplayName(uuid) + "'s luscious ass!");
               
            }
            reset();
            state default;
        }
    }
    timer()
    {
        reset();
        state default;
    }
}

It has worked up until now and now it gives me an error. The error i get is: llDialog: button labels must be 24 or fewer characters long  

Edited by DarkEmperor13
Link to comment
Share on other sites

It is as the error says. llDialog buttons have to be under a certain length. Since your buttons are based on avatar names, the error comes up if a nearby avatar has a long name. To fix it, you can do what Xiija suggested, but you'll find that the name in your chat message will be cut off. You could try using only their first name, or something else.

Link to comment
Share on other sites

25 minutes ago, Wulfie Reanimator said:

It is as the error says. llDialog buttons have to be under a certain length. Since your buttons are based on avatar names, the error comes up if a nearby avatar has a long name. To fix it, you can do what Xiija suggested, but you'll find that the name in your chat message will be cut off. You could try using only their first name, or something else.

what do u mean?

  • Confused 1
Link to comment
Share on other sites

Getting the uuid of a nearby avatar with a dialog menu is enough of a pain that I have a plug-in script I wrote that handles it automatically and I just pass it link messages from the main script.

Edited by Quistessa
Link to comment
Share on other sites

3 hours ago, DarkEmperor13 said:

the whole use first name thing

What  @Wulfie Reanimator  (likely) means is that instead of sending the whole name to the buttons, you can find the position of the first space you find and just take the bit up until that position.  You can use llSubStringIndex to return the zero-based position of the space (in my case, Bugs Larnia, that would be position 4) and copy the part of the name from index 0 to one position before the space.

That would give you the avatar's first name to put in the button, which is far less likely to exceed 24 characters.

Edited by Bugs Larnia
Fixed index number of space character
  • Thanks 1
Link to comment
Share on other sites

Many "residents" have a first and lastname in their firstname - that explains the long names and makes it useless to use firstnames only.
A button holds about 12-14 characters so cutting the names to 24 is no visible loss.
There are other ways to display names in a menu but this menu is made the most simple way so I assume limiting the length is the easiest way.

uuidList is not deleted and will grow until the script runs out of memory. That can take quite a while but it will happen.

The radar scans at 96m range but you are heared only 20m around. Adjustment makes sense.

Link to comment
Share on other sites

Here's one of my earlier (Hmm, description says last xmas eve. . .) scripting projects ( mostly re-using code by Void Singer ) that responds to a link message having integer argument 1 and the key of a person to dialog, with a link message having integer argument -1 and the key of a nearby agent selected via dialog menu:

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),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);
    }
}

and you call it from another script in the same object like so:

uAction(key ID)
{ // your code does something here.
}

default
{
    touch_start(integer total_number)
    {
        llMessageLinked(LINK_THIS,1,"",llDetectedKey(0)); //settarget dialog.
    }
    link_message(integer link,integer n,string text,key ID)
    {
        if(n==-1) // settarget
        {
            uAction(ID);
        }
    }
}

Maybe not the best or most efficient approach, but getting the key of a nearby avatar (or object, or item from a list , both very similar in concept and execution.) is something that comes up often enough, and is just cumbersome enough that it can be worth saving the brainpower of re-implementing a dialog system every time you need to do that.

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1051 days.

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
 Share

×
×
  • Create New...