Jump to content
You are about to reply to a thread that has been inactive for 1287 days.

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

Recommended Posts

Since some people find processing and comparing lists a bit daunting (and it took me some time to learn how to do it),here's an example of how I'd approach the problem (I've just written it now and not tested it).   Note that the scanner needs to be on the parcel it's checking and also that it will notify you each time an avatar enters the parcel (so if the avatar keeps on stepping on the parcel, then off it and then back on, you will be notified each time).    

If that's not the desired behaviour, you will need to do something more complex with strided lists, to keep track of how long the avatar has been away from the parcel, but I don't want to complicate the example unnecessarily.  

key kThisParcel;
key k;
list lOld;
integer max;
float fTimer = 1.0;

default {

	state_entry() {
		kThisParcel = llList2Key(llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_ID]),0);
		llSetTimerEvent(fTimer);
	}

	on_rez(integer start_param) {
		llResetScript();
	}
	timer() {
		llSetTimerEvent(0.0);//it's my habit to turn off the timer event when processing lists in case I need to do something that sleeps the script (e.g. have the script send instant messages or emails)
		if(lOld != []){//if there was anyone on the list last time I looked
			max = llGetListLength(lOld);
			do{ //loop backwards through lOld, starting at the end
				k = llList2Key(lOld, max);
				if(llGetAgentSize(k) == ZERO_VECTOR){ // this av is no longer on the region
					lOld = llDeleteSubList(lOld, max,max);//so remove the av from the list
				}
				else if (llList2Key(llGetParcelDetails(llList2Vector(llGetObjectDetails(k, [OBJECT_POS]), 0),[PARCEL_DETAILS_ID]),0) != kThisParcel){
					//get the avatar's position and check the parcel UUID for where that is. If it's not the same as this parcel's uuid
					lOld = llDeleteSubList(lOld, max,max);
				}
			}
			while(--max > -1);
		}
		list lNew = llGetAgentList(AGENT_LIST_PARCEL, []);//get uuids of avatars currently on parcel
		if(lNew !=[]){//if there's anyone on the parcel
			max = -llGetListLength(lNew);
			do{ //loop through lNew
				k = llList2Key(lNew, max);
				if(!~llListFindList(lOld, [k])){//k is not on lOld, so must have just arrived
					llOwnerSay(llGetUsername(k)+" has just arrived on the parcel.");
					lOld +=[k];//add k to the list of people already on the parcel
				}
			}
			while(++max);
		}
		
		llSetTimerEvent(fTimer);//turn the timer back on
	}
}

 

  • Like 1
Link to post
Share on other sites

Innula, that's kind of you.

I know the usual "not going to do the work for you" etiquette is standard practice, but when it's something that tedious to learn it's really nice to have a little something to work with.

*adds it to her "Utilities & Educational" folder*

That's going to come in very handy someday, I know it. ^-^

Edited by Berksey
Link to post
Share on other sites

I'm never too sure about where to draw the line with "not going to do the work for you."    

The general idea, at least as I understand it, is that we don't want to encourage people to ask for scripts here for free when they should be posting in Employment or Wanted or somewhere and offering to pay for the scripts.  

We also want to encourage people to learn, and you learn best by working it out for yourself, and it's certainly a great feeling when you manage to put it together.

However, having said all that, when it's something that I regard as an important technique to know  and it's something I know from experience is tricky and -- as you rightly say -- "tedious" to learn by working it out for yourself, I don't mind posting a full example in the hope it proves useful and that some people, at least, will take the time to look at the comments and learn how it works.

 

Edited by Innula Zenovka
  • Like 3
Link to post
Share on other sites

I agree.  The early denizens of this forum established the practice of providing only partial scripts or illustrative examples, and we have kept on with it for as long as SL has been around.  As you say, it's meant to keep us from undercutting other scripters who might like a chance to write a script for pay.  It's a logical companion to the community standard that forbids advertizing in the forums. 

As you say, too, the practice makes good sense from an education point of view.  I spent long enough teaching to know that it's usually poor form to tell a student the answer to a question he ought to be figuring out for himself.  It robs the student of the joy of discovery and usually means that the student won't have the tools to solve similar problems in the future.  I prefer to offer a couple of pointers -- maybe a snippet of code -- and shove the student in the right direction, hands off.  If I have a full-blown example to share, I post it in the Library.

There's no "rule" here, but this understanding among us has served the Scripting forum well for a long time.  Circumstances vary, so we are neither rigid nor consistent about how much free scripting we post here.  I'm sure we each have different feelings about how important it is to maintain the norm, too.  There are certainly other forums where it's common to post complete scripts, so there's nothing to say that our approach is necessarily the best.  Personally, though, it served me well when I was starting out with LSL, so I'll stick with it.

Edited by Rolig Loon
  • Like 3
Link to post
Share on other sites

Yeah, it's like if there's a link to it, give them the link. If it's already free somewhere for the public, give them the link. Even if it's just a helping hand with the right thing to look up on the wiki. I've learned an awful lot just following suggestions given in past questions before I ever thought to ask a question here, and often it was simply a link to the page with the function I needed to learn about to do the job.

And if they say hey, I need a script that does this that and the other and I can't find one free on the marketplace, give me one, having the employment forum to refer them to is an awesomely polite way of dealing with it, and might even help people get a few scripting jobs, too, who knows? ^-^

I think it's great we have the Library too, because I wouldn't feel like I was cheating anyone of a chance to learn by directing them there. Even if the script they find already works, they're probably going to end up wanting to change it to suit themselves anyway, I know I always have. I tend to see the library as a collection of examples to learn from too.

But yeah, digging in and learning it from the guts out is the best. I can't even install a simple light bulb without it turning into some sort of Rube Goldberg Frankenstein's monster contraption and finally devolving into something practical and usable again. ^-^; I'm just happy you guys are here to share some of what you know and help some of the rest of us learn. It makes a huge difference.

Link to post
Share on other sites

Is there any speed advantage using:

if(lOld != [])

Else code as below is clearer:

max = llGetListLength(lOld);
if (max > 0 )
{
    do
    {
    }
    while(--max > -1);
}

 

Edited by Rachel1206
Link to post
Share on other sites

You would have to run tests to see how much faster as a lot of other factors involved (amount of data to process etc). In this case as its a one second timer my gut instinct as ever would be to go with the clearer version - but my LSL ninja skills are no match for others (I did all that back in my Mcode days ta=^^= ) so I prefer to make it easier for me to read later. YKMV

Link to post
Share on other sites
8 hours ago, Rachel1206 said:

Is there any speed advantage using:

if(lOld != [])

There used to be, in pre-Mono days.  When I started with LSL, back in 2007, I learned that form from Void Singer along with several hacks that were widely-used at the time. A year or two ago, the question came up  in the SLU scripting forum and the general opinion was that there's no speed advantage now.  You'll still find many of of us who still use it out of habit (and because it doesn't take as long to type).

Edited by Rolig Loon
  • Like 1
Link to post
Share on other sites
2 hours ago, Rolig Loon said:

There used to be, in pre-Mono days.  When I started with LSL, back in 2007, I learned that form from Void Singer along with several hacks that were widely-used at the time. A year or two ago, the question came up  in the SLU scripting forum and the general opinion was that there's no speed advantage now.  You'll still find many of of us who still use it out of habit (and because it doesn't take as long to type).

OK, thank you for giving insight on history behind.

Link to post
Share on other sites

You can also compare list hashes and replace the list if the hashes don't match. Saves you from having to loop through the list checking for agents that left the parcel every timer event.

list AGENTS;
string md5;
default
{
    state_entry()
    {
        llSetTimerEvent(2.0);
    }
    on_rez(integer i)
    {
        llResetScript();
    }
    timer()
    {
        list GAL;
        if ((md5 = llMD5String(llDumpList2String(GAL = llGetAgentList(AGENT_LIST_PARCEL,[])," "),111)) != md5)
        {
            key k = NULL_KEY;
            integer i = -llGetListLength(GAL);
            for (; i < 0; i++)
            {
                //ghost detection: certain ghosts are seen by llGetAgentList(), one returns NULL_KEY, others a correct agent key, but none are seen by llGetAgentSize()
                if ((llGetAgentSize(k) != ZERO_VECTOR) && (llListFindList(AGENTS,[k = llList2Key(GAL,i)]) == -1))
                {
                    llOwnerSay(llKey2Name(k) + " has just arrived on the parcel.");
                }
            }
            AGENTS = GAL;
        }
    }
}

 

  • Like 3
Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 1287 days.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...