Jump to content

Using sensor to populate dialog box of nearby avatars


SEMaster Aftermath
 Share

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

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

Recommended Posts

I am trying to use a sensor that will find avatars within 10 meters, and when touched will give a dialog menu of the nearby avatars (my problem is the names being to large for the buttons). In my example below, I am simply using an llOwnerSay to tell me the name of the avatar that was chosen, and their key to check my work. I keep getting an error message about the sensed avatar's name being more than 24 characters.

Please help,

 

list    nameList;
integer gListener;

default
{
    touch_end(integer num_detected)
    {
        llSensor("", NULL_KEY, AGENT_BY_LEGACY_NAME, 64.0, PI);
    }
    sensor (integer num_detected)
    {
        string names = llDetectedName(0);
        integer index = 1;
        while (index < num_detected)
            names += ":" + llDetectedName(index++);
        nameList = llParseString2List(names,[":"],[]);
        llListenRemove(gListener);
        gListener = llListen(-99,"",llGetOwner(),"");
        llDialog(llGetOwner(),"Pick name",nameList,-99);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(channel == -99)
        {
            key tgt = llName2Key(message);
            llOwnerSay("You selected " + message + " with a key of " + (string)tgt);
            llSetTimerEvent(10.0);
        }
        llSetTimerEvent(10.0);
    }
    timer()
    {
        llListenRemove(gListener);
        return;
    }
}

Link to comment
Share on other sites

6 minutes ago, Wulfie Reanimator said:

One of the easier things to do would be to show a list of names in the menu's message area, with the buttons showing matching numbers for each name.

As a crude example, the dialog would look like:

1. Wulfie Reanimator

2. SEMaster Aftermath

[1] [2]

 

That is a great idea Wulfie, thank you for the suggestion. Would definitely get around the character limit for buttons. How would I assign button number to the specific avatar?

Link to comment
Share on other sites

37 minutes ago, SEMaster Aftermath said:

That is a great idea Wulfie, thank you for the suggestion. Would definitely get around the character limit for buttons. How would I assign button number to the specific avatar?

The numbers would correspond with the index in "nameList" in your example.

When a user picks the button that says "2", you choose llList2String(nameList, 2);

Link to comment
Share on other sites

For this specific functionality on personal projects, I'll usually just use 'chat links' which, are arguably less user-friendly, but have fewer scripting caveats.

Roughly:

gKeyMenuer; // the person using the menu.
gChanMenu; // the menu channel
gSensorTag = "nearby avatar"; // code for why the sensor is happening, and what to expect in the listen event.
sensor(num)
{	llRegionSayTo(gKeyMenuer,0,"Right-click -> 'run this command' on the "+gSensorTag+" to select:");
    while(~--num)
    {   llSleep(0.1); // need to be careful about not tripping sayTo throttle.
        key ID = llDetectedKey(num);
        string name = llKey2Name(ID);
        llRegionSayTo(gKeyMenuer,0,"[secondlife:///app/chat/"+(string)gChanMenu+"/"+llEscapeURL(gSensorTag)+","+(string)ID+" "+name+"]");
    }
}

you can also have an agent/inspect SLURL as well as the chatlink SLURL for a bit of extra clarity.

20 minutes ago, KT Kingsley said:

includes a code snippet that'll trim strings including multi-byte characters to 24 bytes.

I only skimmed it, but I don't see that on the cited page. The last time I tried to implement that, I used some new linkset data functions which happen to count bytes rather than characters.

Link to comment
Share on other sites

34 minutes ago, Quistess Alpha said:

I only skimmed it, but I don't see that on the cited page. The last time I tried to implement that, I used some new linkset data functions which happen to count bytes rather than characters.

It's in the most indented items under the "buttons limits" heading:

Quote

any list item string length (measured in bytes, using UTF-8 encoding) is zero or greater than 24.

  • In other words, a button's text when encoded as UTF-8 cannot be longer than 24 bytes or a empty string.
  • This snippet can be used to truncate the string without giving an error: llBase64ToString(llGetSubString(llStringToBase64(theString), 0, 31))

 

  • Thanks 1
Link to comment
Share on other sites

3 hours ago, Rolig Loon said:

Peruse the LSL Scripting Library for scripts that do exactly that. There are several.

I must be missing something, unable to find any examples or help on how to have the sensor scan an area > assign scanned avatars to buttons in a dialog box > do something with the information on the avatar once clicked from the dialog box.

The piece of script I have and posted in the original post works perfectly...unless someone's name is too long. I guess I just need to play around with it and figure out where to llGetSubString part of the name, but the button still coordinate with the avatar. When I try to llGetSubString a name...it returns the key of that name as all zeros (because the name is not real).

Link to comment
Share on other sites

So, now I have the problem of names on the buttons being too long solved (yay). My problem now, is that when I choose a name from the dialog box, it is not associating that name with the appropriate avatar key. I know it has to have something to do with the index number, but I am lost.

string    gFullName;
string    gShortName;
key        gTgt;
list    gShortNameList;
integer    gListener;



default
{
    state_entry()
    {
        myChan = (integer)("0xF" + llGetSubString(llGetOwnerKey(llGetOwner()),0,6));
    }
    touch_end(integer num_detected)
    {
        llSensor("",NULL_KEY,AGENT_BY_LEGACY_NAME,10.0,PI);
    }
    sensor(integer num_detected)
    {
        gFullName = llDetectedName(0);
        gShortName = llGetSubString(gFullName,0,11);
        gTgt = llName2Key(gFullName);
        integer index = 1;
        while(index < num_detected)
        {
            gShortName += ":" + (llGetSubString(llDetectedName(index++),0,11));
        }
        gShortNameList = llParseString2List(gShortName,[":"],[]);
        llListenRemove(gListener);
        gListener = llListen(myChan,"",llGetOwner(),"");
        llDialog(llGetOwner(),"\nChoose target",gShortNameList,myChan);
    }
    listen(integer channel, string name, key id, string message)
    {
        if(channel == myChan)
        {
            llOwnerSay("You selected " + message);
            llOwnerSay("The key is " + (string)gTgt);  << this is where my problem is. It keeps returning the key of the first name on the list, not necessarily the name I chose.
        }
    }
}

Link to comment
Share on other sites

1 hour ago, SEMaster Aftermath said:

integer index = 1;
        while(index < num_detected)
        {
            gShortName += ":" + (llGetSubString(llDetectedName(index++),0,11));
        }

index should start at 0, and you want to populate another global list (or make your list 2-strided) to contain the keys so you can associate them with the names.

Link to comment
Share on other sites

This is from an example I made ages ago.   I used llGetAgentList because I didn't want to worry about llSensor's limits, but that's not material.

Anyway, instead of using stridied lists, I built two lists when I called llGetAgentList

      key k = llList2Key(lTemp,iMax);
      lNames +=[llGetDisplayName(k)];
      lUUIDs +=[k];

I used the example that Rolig posted above to generate number buttons corresponding to a list of names in the llDialog caption, and then, in the listen event, when user chose a number, I looked up the corresponding name and key thus

        integer n = (integer)message -1;
        llRegionSayTo(kToucher, 0, "You chose: " + strChoice = llList2String(lNames,n)+", uuid "+(string)(kChosenUUID = llList2Key(lUUIDs, n)));

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 251 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...