Jump to content

Turret Targeting Issue


LeonissiaLoc
 Share

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

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

Recommended Posts

How can I get this to detect avatars using llGetAgentList? 

integer listener;
integer sensorChannel; 
list avatarsKeys;
list avatarsNames;
integer touched;
menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
}
integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}
default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            llSensor("","",AGENT,96,PI);
        }
        
    }
    sensor(integer total_number)
    {
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        while ((i < total_number) && (i < 12))
        {
            tempId = llDetectedKey(i);
            avatarsKeys = avatarsKeys + tempId;
            avatarsNames = avatarsNames + llKey2Name(tempId);
            i = i+1;
        }
        sensorChannel = randomNumber();
        menu(llGetOwner(),sensorChannel,"Select an avatar...",avatarsNames);
    }
       listen(integer channel,string name,key id,string message)
    {
        if (channel == sensorChannel)
        {
            llSetTimerEvent(0.05);
        }         
    }
  touch(integer total_number)
    {
        llSetTimerEvent(0.0);
    }
    timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
vector vPos=llGetPos();
 llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);
list hit = llCastRay(vPos, vTargetPos, []);
if( llKey2Name(llList2Key(hit, 0)) != "RC" )
{
    llRezObject("bullet", llGetPos()+<0,0,3>*llGetRot(),<0,0,20>*llGetRot(),llGetRot(),0);
}
if( llGetOwnerKey(llList2Key(hit, 0)) == llGetOwner() )
{
   return;
}
    } 
} 

 

Edited by LeonissiaLoc
I meant detect avatars instead of track, sorry.
Link to comment
Share on other sites

Quote

integer listener;
integer sensorChannel; 
list avatarsKeys;
list avatarsNames;
integer touched;
menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
}
integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}
default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            llSensor("","",AGENT,96,PI);
        }
        
    }
    sensor(integer total_number)
    {
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        while ((i < total_number) && (i < 12))
        {
            tempId = llDetectedKey(i);
            avatarsKeys = avatarsKeys + tempId;
            avatarsNames = avatarsNames + llKey2Name(tempId);
            i = i+1;
        }
        sensorChannel = randomNumber();
        menu(llGetOwner(),sensorChannel,"Select an avatar...",avatarsNames);
    }
    listen(integer channel,string name,key id,string message)
    {
        if (channel == sensorChannel)
        {
            llSetTimerEvent(0.05);
        }         
    }
    touch(integer total_number)
    {
        llSetTimerEvent(0.0);
    }
    timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
       vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
       vector vPos=llGetPos();
       llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);
       list hit = llCastRay(vPos, vTargetPos, []);
       if( llKey2Name(llList2Key(hit, 0)) != "RC" )
       {
            llRezObject("bullet", llGetPos()+<0,0,3>*llGetRot(),<0,0,20>*llGetRot(),llGetRot(),0);
       }
       if( llGetOwnerKey(llList2Key(hit, 0)) == llGetOwner() )
       {
            return;
       }
   } 
}

 

First, is it just my browser, or is the code section of your posts in black text on a black background? Anyway, to be able to see it without keeping it all selected all the time, I've re-posted it above without change (and just a bit of indentation formatting near the end).

You asked how to use llGetAgentList() to track avatars, but that function identifies avatars in the region -- analogous to how the above script's llSensor() function finds a potential target. As above, you'd use llGetObjectDetails(...OBJECT_POS...) to track the avatar's position. The simplest change would be to replace llSensor() with the llGetAgentList() function call, and use the list it returns as the avatarsKeys list from the sensor() event handler which you won't be needing anymore.

The avatarsNames list (for the menu) will need to be generated by walking through the avatarsKeys() list. Probably you'll want to truncate the lists to twelve elements, as the sensor version does, to keep the menus to a single page. A complexity here is that the sensor() event gets its results in order of increasing distance, but llGetAgentList() results are in no specified order, so if this will be operating in "target rich" environments, you'll want to keep just the nearest ones.

Now then, about this script:

  • I don't understand why the touch() event is being used to stop the timer; those are pretty tricky events to work with, compared to touch_start and touch_end, especially combined in the same state, so... I'm not actually sure what's intended here for stopping the bullets flying.
  • As it stands, the menu result isn't actually used for anything. Instead, the timer() code targets the -1-indexed element of the avatarsKeys list (I guess). I imagine the idea was to store the menu-chosen name from listen() in a global variable, and find it in the avatarsNames list, but that's not what it's doing yet.
  • Also, calling llListen() in menu() without removing the listener from the previous time the function was called will soon enough use up all listeners the script can have.
Link to comment
Share on other sites

So far I have this, but I'm having trouble figuring out the avatarsName part.

integer listener;
integer sensorChannel;
list avatarsKeys;
list avatarsNames; 
integer touched;
menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
}
integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}
default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        integer numOfAvatars = llGetListLength(avatarsInRegion);
 
        // if no avatars, abort avatar listing process and give a short notice
        if (!numOfAvatars)
        {
            llOwnerSay("No avatars found within the region!");
            return;
        }
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        integer index;
        while ((i < total_number) && (i < 12))
        {
            tempId = llDetectedKey(i);
            avatarsKeys = avatarsKeys + tempId;
            avatarsNames = avatarsNames + llKey2Name(tempId);
            i = i+1;
            key id = llList2Key(avatarsInRegion, index);
            string name = llKey2Name(id);
 
            llOwnerSay(name + " [ " + (string)id + " ]");
            ++index;
        }
        sensorChannel = randomNumber();
        menu(llGetOwner(),sensorChannel,"Select an avatar...",avatarsInRegion);
    }
    listen(integer channel,string name,key id,string message)
    {
        if (channel == sensorChannel)
        {
            llSetTimerEvent(0.05);
        }   
        }touch(integer total_number)
    {
        llSetTimerEvent(0.0);
        llListenRemove(0);
    }
    timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
vector vPos=llGetPos();
 llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);
list hit = llCastRay(vPos, vTargetPos, []);
if( llKey2Name(llList2Key(hit, 0)) != "RC" )
{
    llRezObject("bullet", llGetPos()+<0,0,3>*llGetRot(),<0,0,20>*llGetRot(),llGetRot(),0);
}
if( llGetOwnerKey(llList2Key(hit, 0)) == llGetOwner() )
{
   return;
}      
    }
}

 

Edited by LeonissiaLoc
Link to comment
Share on other sites

1 hour ago, LeonissiaLoc said:

So far I have this, but I'm having trouble figuring out the avatarsName part.


integer listener;
integer sensorChannel;
list avatarsKeys;
list avatarsNames; 
integer touched;
menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
}
integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}
default
{
    touch_start(integer total_number)
    {
        list avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
        integer numOfAvatars = llGetListLength(avatarsInRegion);
 
        // if no avatars, abort avatar listing process and give a short notice
        if (!numOfAvatars)
        {
            llOwnerSay("No avatars found within the region!");
            return;
        }
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        integer index;
        while ((i < total_number) && (i < 12))
        {
            tempId = llDetectedKey(i);
            avatarsKeys = avatarsKeys + tempId;
            avatarsNames = avatarsNames + llKey2Name(tempId);
            i = i+1;
            key id = llList2Key(avatarsInRegion, index);
            string name = llKey2Name(id);
 
            llOwnerSay(name + " [ " + (string)id + " ]");
            ++index;
        }
        sensorChannel = randomNumber();
        menu(llGetOwner(),sensorChannel,"Select an avatar...",avatarsInRegion);
    }
    listen(integer channel,string name,key id,string message)
    {
        if (channel == sensorChannel)
        {
            llSetTimerEvent(0.05);
        }   
        }touch(integer total_number)
    {
        llSetTimerEvent(0.0);
        llListenRemove(0);
    }
    timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
vector vPos=llGetPos();
 llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);
list hit = llCastRay(vPos, vTargetPos, []);
if( llKey2Name(llList2Key(hit, 0)) != "RC" )
{
    llRezObject("bullet", llGetPos()+<0,0,3>*llGetRot(),<0,0,20>*llGetRot(),llGetRot(),0);
}
if( llGetOwnerKey(llList2Key(hit, 0)) == llGetOwner() )
{
   return;
}      
    }
}

I can't find a way to replicate the black-on-black effect even with the forum switched to a dark theme, so... anyway, there it is in black-and-white, as it were.

There's just a lot wrong here, and I'm not sure how to help. I guess, first, the assignment of tempId to llDetectedKey(i) isn't going to work because the llDetected* functions in a touch-related event relate to the toucher. Instead, you'll want to use elements in the avatarsInRegion list. Again, if there are a lot of avatars in the region, your menu must only show at most 12 at a time, so eventually you may want to choose those 12 wisely, but however you do it, you don't want to use the full list of avatars in the region (up to 100 of which may be returned by llGetAgentList).

So probably you mean to copy up to 12 keys from avatarsInRegion into avatarsList. The "up to" part here is because avatarsInRegion may have fewer than 12 elements; you've already found out how many it has in numOfAvatars, so to handle the less-than-12 elements condition you can test i < numOfAvatars instead of total_number (which is the number of distinct touch_start occurrences that are being handled, which will always be 1).

[ETA: Another part of this first step: the menu will want to use the avatarsNames list instead of a list of keys, and the names must fit within the maximum character count for a dialog button, so those avatarsNames elements will need to be chopped to size with llGetSubString() applied to the result of llKey2Name().]

There's more, but maybe that's enough to start.

Edited by Qie Niangao
Link to comment
Share on other sites

How can I get this to target another avatar instead of me when I select a  foreign target? I tried a lot of stuff with it and can't get it to work. Thanks.

 

 

 

integer listener;
integer sensorChannel; 
list avatarsKeys;
list avatarsNames;
integer touched;
menu(key user,integer channel,string title,list buttons)
{
    listener = llListen(channel,"","","");
    llDialog(user,title,buttons,channel);
}
integer randomNumber()
{
    return (integer)(llFrand(99999.0) * -1);
}
default
{
    touch_start(integer total_number)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            llSensor("","",AGENT,96,PI);
        }
        
    }
    sensor(integer total_number)
    {
        integer i;
        key tempId;
        avatarsKeys = [];
        avatarsNames = [];
        i = 0;
        while ((i < total_number) && (i < 12))
        {
            tempId = llDetectedKey(i);
            avatarsKeys = avatarsKeys + tempId;
            avatarsNames = avatarsNames + llKey2Name(tempId);
            i = i+1;
        }
        sensorChannel = randomNumber();
        menu(llGetOwner(),sensorChannel,"Select an avatar...",avatarsNames);
    }
       listen(integer channel,string name,key id,string message)
    {
        if (channel == sensorChannel)
        {
            llSetTimerEvent(0.05);
        }         
    }
  touch(integer total_number)
    {
        llSetTimerEvent(0.0);
    }
    timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
vector vPos=llGetPos();
 llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);
list hit = llCastRay(vPos, vTargetPos, []);
if( llKey2Name(llList2Key(hit, 0)) != "RC" )
{
    llRezObject("bullet", llGetPos()+<0,0,3>*llGetRot(),<0,0,20>*llGetRot(),llGetRot(),0);
}
if( llGetOwnerKey(llList2Key(hit, 0)) == llGetOwner() )
{
   return;
}
    } 

Link to comment
Share on other sites

I'm sorry to say this, but you need to commit to learning more about scripting. You can't just post the same script in different threads expecting people to change it for you. If you just want a turret script you might either buy one, find one that actually works, or hire somebody to make one for you. If on the other hand you want to learn how to script one yourself, you're in the right place, but I don't think you'll get satisfactory results without investing a little more effort in understanding how the scripts you're posting actually work -- then you could ask about what specifically isn't working with your changes.

Of course, if you keep trying, somebody may post a script that (accidentally) does exactly what you want. And that would be a failure in this forum because then you wouldn't learn anything about scripting.

  • Like 1
Link to comment
Share on other sites

6 hours ago, Qie Niangao said:

I'm sorry to say this, but you need to commit to learning more about scripting. You can't just post the same script in different threads expecting people to change it for you. If you just want a turret script you might either buy one, find one that actually works, or hire somebody to make one for you. If on the other hand you want to learn how to script one yourself, you're in the right place, but I don't think you'll get satisfactory results without investing a little more effort in understanding how the scripts you're posting actually work -- then you could ask about what specifically isn't working with your changes.

Of course, if you keep trying, somebody may post a script that (accidentally) does exactly what you want. And that would be a failure in this forum because then you wouldn't learn anything about scripting.

I was trying to do two different things with the same script. The other post was me trying to replace the sensor with llGetAgentList();, but then I discovered that my current script has a targeting issue with the sensor so it probably wouldn't work right with llGetAgentList(); not until I can get the targeting to work with the sensor. I'm trying to use this to learn how all the functions work together and understand how the math works. I'm not asking that anyone do the work for me. I'm looking for help kinda like what I found in this example. I just don't know how to speak LSL effectively yet. I understand a lot of the logic part, but it's the math that is stumping me the most. I keep looking and looking at the script, researching the different functions and I still can't get my head around it. I may be pushing myself a little too much and I'm just missing something. If this is the wrong way to go about asking for help, please let me know. I don't want to come off like I'm trying to get y'all to do the work for me, I want to learn how this works. Any advice is appreciated and I understand beginners like me make a lot of mistakes and y'all probably get a bunch of people trying to get ya'll to do the work for them, I don't want to be like that. Thank you.

Link to comment
Share on other sites

20 hours ago, LeonissiaLoc said:

  timer()
    {
       integer index = llListFindList(avatarsNames,[]);
       key kTarget = llList2Key(avatarsKeys,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);

OK, here's one place to start thinking through the logic.  The function llListFindList looks for the position of its second list parameter in the first list parameter. In this case, your statement

integer index = llListFindList( avatarsNames ,[]);

means "Find the position of [] in the list avatarsNames."  That's going to be difficult, because [] is an empty list, so index will have the value -1, meaning "not there".  In another sense, the integer -1 means "the last element in the list."  So, when you use index in the next two statements, you will be looking for the last element in avatarsNames.  That's almost certainly not what you want to do.  To script it to do what you do want, however, means doing a major rewrite of the rest of the script.  The avatar that you really want to target is the one you will identify in the llDialog.  The answer to that query, though, will be in the listen event, where you haven't provided any code to receive it.  And so it goes.  Steph has offered an interesting suggestion that will probably make it easier to keep track of matched variables but is not really at the heart of your major issues here.  There are other things like that that you should probably address too.  For now, though, the simple answer is that the reason it's only targeting you is that your script seems to have used that definition of index to point at the last person on the detected list.

It's hard to know where to start, except to say that you would be better off starting fresh, writing your own script instead of trying to modify someone else's.  Once of the most basic rules is "don't use someone else's code unless you understand exactly what it does."

  • Like 1
Link to comment
Share on other sites

11 hours ago, Rolig Loon said:

OK, here's one place to start thinking through the logic.  The function llListFindList looks for the position of its second list parameter in the first list parameter. In this case, your statement

integer index = llListFindList( avatarsNames ,[]);

means "Find the position of [] in the list avatarsNames."  That's going to be difficult, because [] is an empty list, so index will have the value -1, meaning "not there".  In another sense, the integer -1 means "the last element in the list."  So, when you use index in the next two statements, you will be looking for the last element in avatarsNames.  That's almost certainly not what you want to do.  To script it to do what you do want, however, means doing a major rewrite of the rest of the script.  The avatar that you really want to target is the one you will identify in the llDialog.  The answer to that query, though, will be in the listen event, where you haven't provided any code to receive it.  And so it goes.  Steph has offered an interesting suggestion that will probably make it easier to keep track of matched variables but is not really at the heart of your major issues here.  There are other things like that that you should probably address too.  For now, though, the simple answer is that the reason it's only targeting you is that your script seems to have used that definition of index to point at the last person on the detected list.

It's hard to know where to start, except to say that you would be better off starting fresh, writing your own script instead of trying to modify someone else's.  Once of the most basic rules is "don't use someone else's code unless you understand exactly what it does."

I got my new script to do the basic select avatars and use one list instead of two. What do I need to study to get the listen event to receive the avatar tracking info when I select an avatar?

Link to comment
Share on other sites

19 minutes ago, LeonissiaLoc said:

I got my new script to do the basic select avatars and use one list instead of two. What do I need to study to get the listen event to receive the avatar tracking info when I select an avatar?

The strided list will contain paired information you need. The second is the agents name. That information if for you because it is user freindly and is used for the menu button. The first is the key of that agent which the script function needs. You need to read this http://wiki.secondlife.com/wiki/Category:LSL_List

Before you can do anyting you need to sort the list part out. Once that is correct then using the information can be delt with.

Link to comment
Share on other sites

After I study LSL long enough and it clicks, will I be able to program anything I think of? Is it the same for all programming languages? How do you know what to do when you get stuck for lack of knowledge and don't know what to look up? Do I just ask on here on how to program a billion different scripts until I finally get it? How does all this work? I don't understand why this is so complicated to wrap my head around. How did y'all do it? Thanks for all the help thus far.

Edited by LeonissiaLoc
Link to comment
Share on other sites

Just now, LeonissiaLoc said:

After I study LSL long enough and it clicks, will I be able to program anything I think of? Is it the same for all programming languages? How do you know what to do when you get stuck for lack of knowledge and don't know what to look up? Do I just ask on here on how to program a billion different scripts until I finally get it? How does all this work? I don't understand why this is so complicated to wrap my head around.

The prime part of your script is list manipulation. Lists are fundimental in many scripts. From object givers, yours, rezzers etc. The scanner data in this script is a data gatherer. If you kludge someone elses scripts you will never get anywhere because you are just hammering code with no understanding.

Link to comment
Share on other sites

4 minutes ago, steph Arnott said:

The prime part of your script is list manipulation. Lists are fundimental in many scripts. From object givers, yours, rezzers etc. The scanner data in this script is a data gatherer. If you kludge someone elses scripts you will never get anywhere because you are just hammering code with no understanding.

When I am hammering code, I'm also looking up the functions. I seem to not be able to understand what seems to be abstract. Anything with a practical sense or what I've already reverse engineered I can figure out pretty easily. I guess I need to read the wiki about the functions two million times and ask y'all about it for me to get it to click.

Link to comment
Share on other sites

7 minutes ago, LeonissiaLoc said:

When I am hammering code, I'm also looking up the functions. I seem to not be able to understand what seems to be abstract. Anything with a practical sense or what I've already reverse engineered I can figure out pretty easily. I guess I need to read the wiki about the functions two million times and ask y'all about it for me to get it to click.

Well not to be a party pooper but you need to write your own work. Using others just instilles all their poorly coded work. Which they probably kludged together using others poorly coded work. When i started i did the same and then decided to start with clean slate.

Link to comment
Share on other sites

1 hour ago, LeonissiaLoc said:

After I study LSL long enough and it clicks, will I be able to program anything I think of? Is it the same for all programming languages? How do you know what to do when you get stuck for lack of knowledge and don't know what to look up? Do I just ask on here on how to program a billion different scripts until I finally get it? How does all this work? I don't understand why this is so complicated to wrap my head around. How did y'all do it? Thanks for all the help thus far.

When you are beginning, it is natural to focus on functions and syntax. It is the same way when you are learning a foreign language. You learn lists of words, hoping that you can communicate by substituting them for words in your own language.  That's not the way that languages work, though, and that technique only gives you a superficial start at learning.  The same is true with writing programs or scripts.  The functions and syntax are important, but the heart of a script is logic. If you do not understand what you want the script to do and cannot put your thoughts into logical terms, all the functions and syntax will not help. Instead of focusing on how to do the job, focus on what to do.

Even after working with LSL for 12 years, I always refer to the wiki descriptions of what each function does and how to make it work.  I do that because I do not care to keep all of that information in my head.  I can look it up any time I need it.  What is in my head is a road map of where I want my script to go.  I think in modular terms, starting at the end of the maze of logic I must construct and looking at what decisions the script will need to make to get there.  When I start writing the script, I attack it in pieces. What sort of information will I need the script to gather? How will it know which information to ignore? How will it know when it should follow one path rather than another?  I begin with a very high-level map in my mind, as if I am viewing a journey from a great height, and then I start filling in the details as I understand the logic that is evolving as I get further into the project.  Scripting is the process of gradually building the logical framework that will explain how the beginning is connected to the end.

Steph is giving you good advice. 

1 hour ago, steph Arnott said:

Well not to be a party pooper but you need to write your own work. Using others just instilles all their poorly coded work. Which they probably kludged together using others poorly coded work. When i started i did the same and then decided to start with clean slate.

Other people's scripts may not be "poorly coded," but at the very least they are not your work.  They don't express how you understand the project. They are someone else's road maps.  Study them for guidance, but write your own scripts. Start writing small things that you can wrap your head around, not things that have so many twists and turns that you will get lost in them. Be patient about practicing small skills.  The script that you have presented here needs so much work that no one here can tell you what to do without completely rewriting it, and that's your job.

Link to comment
Share on other sites

4 hours ago, LeonissiaLoc said:

After I study LSL long enough and it clicks, will I be able to program anything I think of? Is it the same for all programming languages? 

It will click, and then you'll just get stuck occasionally, like all the rest of us, and create bugs you just can't see yourself, like all the rest of us. All programming languages have in common that mere mortals created them for mere mortals to use, and one spends more time fixing stuff that's broken than it takes to create all the broken stuff in the first place. LSL is neither the easiest nor the most difficult programming language, but scripting with it is more challenging than it looks because there are obscure quirks in the library functions -- which we all learn over time and yet still somehow get bitten by, over and over.

Will you be able to program anything you think of? No, not if you have a healthy imagination. But the fun part is discovering a way to program something that seemed impossible at first. Do that a couple of times and you'll be hooked.

Link to comment
Share on other sites

I don't know what to do to get this thing to work. I studied the strided list and I can select the avatar with just the names list. I put the uuid list in there because I can't get the llLookAt() to work with only one list. At "integer index = llListFindList(uuid,[]);" is the only way to track the avatar selected but my avatar is still the one targeted no matter who I select. How do I know what to look up and study so I can fix this what seems to be an impossible challenge? I looked up the functions, but I don't get this. Thanks for your help, any guidance is appreciated. 

list Names;
list uuid;
default
{
    state_entry()
    {
        llListen(10, "", llGetOwner(), "");
        llSensorRepeat("", "", AGENT, 96.0, PI, 0.2);
    }
    touch_start(integer detected)
    {
        if (llDetectedKey(0) == llGetOwner())
        {
            llSetTimerEvent(0.0);
            llListenRemove(10);
            llSensorRemove();
            llSensor("","",AGENT,96,PI);
            llDialog(llDetectedKey(0), "Choose an avatar...", Names, 10);
        }  
    }
     sensor(integer allAvatars)
    {
        integer o;
        key Id;
        Names = [];
        uuid = [];
        o = 0;
        while ((o < allAvatars) && (o < 12))
        {
            Id = llDetectedKey(o);
            uuid = uuid + Id;
            Names = Names + llKey2Name(Id);
            o = o+1;
        }
        
    }
    listen(integer channel, string obj, key id, string message)
    {
        list uuid = llList2ListStrided(Names, 0, -1, 2);
        integer index = llListFindList(Names, [message]);
        if (index != -1)
        {
             llSetTimerEvent(0.05);
        }
    }    
    timer()
    {
        
         integer index = llListFindList(uuid,[]); 
       key kTarget = llList2Key(uuid,index);
vector vTargetPos = llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0);
vector vPos=llGetPos();
 llLookAt(vPos + (vTargetPos + <0.0, 0.0, 0.0> - vPos) / llGetRootRotation(), 1.0, 0);


    } 
}

 

Edited by LeonissiaLoc
Link to comment
Share on other sites

Right about now, the smart thing to do is insert a bunch of llOwnerSay statements to ask the script to tell you what is actually in your various variables at key points. Use llOwnerSay(llList2CSV(uuid)); to find out what's really in that list, for example.  Chance are pretty good that you are grabbing the wrong list element.  Indexing errors are really common and fortunately really easy to find if you just take time to look at what's in the list.

Link to comment
Share on other sites

20 minutes ago, Rolig Loon said:

Right about now, the smart thing to do is insert a bunch of llOwnerSay statements to ask the script to tell you what is actually in your various variables at key points. Use llOwnerSay(llList2CSV(uuid)); to find out what's really in that list, for example.  Chance are pretty good that you are grabbing the wrong list element.  Indexing errors are really common and fortunately really easy to find if you just take time to look at what's in the list.

When there are avatars in the region, it's returning all keys with llOwnerSay(llList2CSV(uuid)); and all names with llOwnerSay(llList2CSV(Names)); at the same time. What should I do to get it to read only the one I select from the llDialog()?

Edited by LeonissiaLoc
Link to comment
Share on other sites

39 minutes ago, LeonissiaLoc said:

What should I do to get it to read only the one I select from the llDialog()?

You already did that.  That's why you wrote

 

1 hour ago, LeonissiaLoc said:

integer index = llListFindList(Names, [message]);

and the following test in the listen event.  Remember?  Put an llOwnerSay test right after 

 

1 hour ago, LeonissiaLoc said:

key kTarget = llList2Key(uuid,index);

to see whether you're looking at the right one.  If not, then you know where you better start looking for the mistake.

Link to comment
Share on other sites

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