Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

removing duplicates from a list

Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
11-13-2006 17:33
Do you have to use sensors at all? If you own the objects you're trying to sense, just have them report their positions by shout periodically.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
11-13-2006 17:35
Oh it's for a model. Then we can do greasy hacks.

I'd use packing.
Using integers for both key & positions give reasonable precision and solves problems with overlap.

CODE

int v2i(vector in)
{//this is a greasy pack function, you can add features to this if you so choose
return ((((integer)in.x & 255) << 16) | (((integer)in.y & 255) << 8) | ((integer)in.z & 255));
}

integer k2i(string a)
{//no reversible
return (integer)("0x"+llGetSubString(a, -8,-1));
}

vector i2v(integer in)
{
return <in >> 16, (in >> 8) & 255, in & 255>;
}

list keys;
list pos;

integer register_a;

updatePos(integer k, integer p)
{
if(~(register_a=llListFindList(keys, [k])))
{
pos = llListReplaceList(pos, [p], register_a, register_a);
}
else
{
keys += k;
pos += p;
}
}

removeKey(integer k)
{
if(~(k = llListFindList(keys, [k])))
{
keys = llDeleteSubList(keys, k, k);
pos = llDeleteSubList(pos, k, k);
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
didn't quite get it reading through here...
09-22-2007 06:32
AHHH! this is precisely what i'm trying to do now, a sim scanner, and am absolutely failing at applying the solutions i've read...

I've got sensors doing 6 PI/3 scans then shouting back to an antenna which tells a rez display what to show, wait 10 seconds, rinse, repeat.

they will obviously have overlaps in one set of 6 and seperate sensor overlap as well... i want to have the probes cull before Regionsaying back, and the antenna accumulate for 30 seconds (whatever makes it in that time), then cull and send to rezzer display.

my attempts at checklist are going badly again... wht i've had working in-world so far either culled nothing (huge strings coming back, rezzed icons refreshing 6 or more times) or culled everything (antenna showed up, as it transmitted "culled list"+it's own stat).

Now i've attempted to put things in from here and borked even that much, so the code i present will probably (last tested state) be absolutely non-functional...

so anyway I have 2 lists, keys and vectors, with repeats (that may not be exactly same vector, obviously).

setting out below probe, antenna and base script.. i wish i understood how Elektra and Strife's bits work, i wish i knew what the tilde does (seen it in a couple of workings on this applied to integer ListFindList but can't find it defined as operator or anything?) and i wish i didn't go crosseyed always at this point, after geting something half-working *sigh*


So here's what's left of the code:

CODE


//sensor probe script, pieced together from many bits on the forums:


/////////
//Global Variables
/////////
integer counter=0;
string NAME;
integer maincount=0;
integer PROBECHAN = -76;
integer TYPE=AGENT;
key KEY;
vector eul;
list com_list;
list tmp_list;
string msg;
list veclist;
vector destin;
///////////
//Functions
///////////
warpPos(vector destin)
{
integer jumps = (integer)(llVecDist(destin, llGetPos()) / 10.0) + 1;
if (jumps > 250 )
{
jumps = 250;
}
list rules = [ PRIM_POSITION, destin ];
integer count = 1;
while (( count = count << 1 ) < jumps)
{
rules = (rules=[]) + rules + rules;
}
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
if (llVecDist(destin, llGetPos()) > 0.01)
{
jumps = (integer)(llVecDist(destin, llGetPos()) / 10.0) + 1;

while ( -- jumps)
{
llSetPos(destin);

}
}
}


Swivel()
{

rotation r = llEuler2Rot( DEG_TO_RAD*eul);

llSetRot(r);
}

process_list ()
{
maincount ++;

integer pings = llGetListLength(com_list);
integer i;

for(i=0;i<pings;i++)
{

llRegionSay(PROBECHAN,llList2String(com_list,i)+"|"+llList2String(veclist,i));


}
com_list=[];
veclist=[];
if(maincount <= 5)
{

llSleep(10) ;


}
else
{
llDie();


}


}

default
{
on_rez(integer start_param)
{

PROBECHAN=start_param;

destin=(vector)llGetObjectDesc();
warpPos(destin);

llSetRot(ZERO_ROTATION);

if(llGetPos()==destin)
{ llSetAlpha(0.0,ALL_SIDES);


llListen(PROBECHAN,"",NULL_KEY,"");

}
if(llGetPos()!=destin)
{


llDie();
}
}

state_entry()
{






counter=0;
llListen(PROBECHAN,"",NULL_KEY,msg);


if(maincount >=4)
{
maincount = 0;
state reset;
}


}


timer()
{

if (counter==0)
{
eul=<0,0,0>;
}

if (counter==1)
{
eul=<0,0,90>;
}
if (counter==2)
{
eul=<0,0,180>;
}
if (counter==3)
{
eul=<0,0,270>;
}
if (counter==4)
{
eul=<0,90,0>;
}
if (counter==5)
{
eul=<0,270,0>;
}
if (counter==6)
{
eul=<0,270,0>;
Swivel();
// llMessageLinked(LINK_SET,0,"off",NULL_KEY);
counter=0;
process_list();


return;
}
Swivel();
llSensor( NAME, KEY, TYPE, 96, PI/3);


counter++;
}
/////////////////////////////////////
sensor ( integer total_number )
{

integer check_list;
integer i;
tmp_list = [];

for ( i = 0; i <total_number; i++ )
{
tmp_list = [(string)llDetectedKey(i)];

string loc=(string)llDetectedPos(i);
check_list = llListFindList (com_list, tmp_list );


if ( check_list == -1 )
{
com_list += [(string)tmp_list];
veclist+= [loc];
}


if (check_list!=-1)
{
tmp_list=[];
}

}


}
////////////////

listen(integer chan, string name, key id,string mes)
{
if(mes=="go")
{
llSetTimerEvent(.2);
}
}



}

state reset
{
state_entry()
{
state default;
}


}


antenna follows.....
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
the antenna
09-22-2007 06:37
This is what i most seriously broke from its semi-functional state (and saved over without making copy - dumb)

CODE


//antenna reciever

integer PROBECHAN = -76;
key id;
string msg;
string bit;
string vdata="";
string wholedata="";
list biglist=[];
list veclist =[];
integer tick=0;
vector mypos;
integer COMCHAN = -67;


default
{
state_entry()
{
mypos=llGetPos();

}


touch_start(integer total_number)
{
llTargetOmega(<0,0,0.1>,PI,1.0);

llSay(0, "Probe antenna ON!");
llRezObject("PROBECLUSTER",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,PROBECHAN);
llListen(PROBECHAN,"",id,msg);
llSleep(5);
llRegionSay(PROBECHAN,"go");
llSetTimerEvent(10);
}


timer()
{
integer c;
integer blab = llGetListLength(biglist);

for(c=0;c<blab;c++)
{

bit+= llList2String(biglist,c)+"|"+llList2String(veclist,c);
}

if(tick<=4)
{

llRegionSay(COMCHAN,bit+(string)llGetKey()+"|"+(string)llGetPos());
biglist=[];
veclist=[];
bit="";
tick++;
}
else
{

llRegionSay(COMCHAN,bit+(string)llGetKey());
biglist=[];
veclist=[];
bit="";
llRezObject("PROBECLUSTER",llGetPos(),ZERO_VECTOR,ZERO_ROTATION,PROBECHAN);
llSleep(5);
llRegionSay(PROBECHAN,"go");
tick=0;
}
}


listen(integer PROBECHAN,string name,key id,string msg )
{


if(msg!="")
{


list r_data=llParseString2List(msg,["|"],[""]);
string rkey=llList2String(r_data,0);

integer check_list;
integer i;
list little_list;
///////////////////////////////
////////////////////////
//////////// Here i really started messing around, had same routine as in probe before --
// don't remember exactly, tried too many things!

little_list = [ rkey];

//biglist= llListSort(biglist, 1, TRUE); //sort the list first

integer l;
integer lsize = llGetListLength(biglist); //get list length
list newbig; //create a new tmp list where to store the results

string last;
for (l=0; l<lsize; l++)
{
string s = llList2String(biglist, l); //element in the list
if (s != last)
{
newbig += ; //add to the new result list
last = s; //set the last element as the current one in the tmp variable "last"
}
}
llOwnerSay((string)newbig + (string)llGetTime());
biglist=newbig;
}





}
//llRegionSay(COMCHAN,bit);
// llRegionSay(COMCHAN,(string)llGetKey()+"|"+(string)llGetPos());
}




{/CODE]
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
and the base
09-22-2007 06:41
here, too i borked something, started touying with the notion of having just keys sent back and trying this GetObjectDetails... and made the changes before finding that it's not even recognized as a command on viewer i've got :-o

i think i managed to put it back; it was in the end part before invoking display, in getting the position data...


CODE


////////////////
//Script: Sensor Shield
////////////////



///////////
//Variables
////////////
integer COMCHAN = -67;
key key_id;
vector position;
vector zero;
float scale;
vector size;
vector place;



///////////////
//Functions
////////////////////

initAnim()
{

llSetTextureAnim(ANIM_ON | SMOOTH| LOOP, ALL_SIDES,0,0,1.0, 0.0,1.7);


}


do_display(key key_id, vector position)
{
size = llGetScale();

scale = size.x/256;

place = <position.x*scale,position.y*scale,position.z*(scale*.5)>;

zero=llGetPos()- <size.x*.5,size.y*.5,size.z*.5>;

vector rez_point =zero+place;

llWhisper(COMCHAN,"refresh"+":"+(string)key_id);
llSleep(0.3);
llRezObject("DotIcon",rez_point,ZERO_VECTOR,ZERO_ROTATION,COMCHAN);
llSleep(0.2);
llWhisper(COMCHAN,"title"+":"+(string)rez_point+":"+(string)key_id+":"+(string)position);
}





///////////////
//States
////////////////

default
{
state_entry()
{
initAnim();
llListen(COMCHAN,"SCC-SA1",NULL_KEY,"");
}


listen(integer chan,string name,key id,string msg)
{
if (msg!="")
{
// llSay(0,msg);
list comm= llParseString2List(msg,["|"],[]);
// key_id= (key)llList2String(comm,0);
integer c;
integer blab = llGetListLength(comm);
for(c=0;c<blab;c=c+2)
{
key_id=(key)llList2String(comm,c);
position= (vector)llList2String( key_id,c+1);
do_display(key_id,position);
}
}




}
}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
09-22-2007 07:11
From: Chrysala Desideri
i wish i knew what the tilde does (seen it in a couple of workings on this applied to integer ListFindList but can't find it defined as operator or anything?)
At least this bit I can help with: it's the bit-flip operator, as defined at .

This thread is bound to end up with the Final Word on scanners, which would be a good thing, to thin out the laggy ones from the grid (at the expense of a few products, possibly--though perhaps the display method can be a differentiator). At this point, I'd only say that the more work done at the sensor in reducing frequency of update to the central display controller, the better. (For example, if a detection has moved less than the display resolution, no point in telling the display controller about it.)
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
09-22-2007 08:03
ok, just to show i'm not insane (enough),

i know that this works:
CODE

string x = "boogie";
list g=["gargantua","collima","zeb","boogie"];
integer check=llListFindList(g,[x]);

if(check==-1)
{
g += x;
integer num=llGetListLength(g);
integer c;
for(c=0;c<num;c++)

{
llSay(0,llList2String(g,c));
}

}

else
{
llSay(0,"nothing added");}
}


and that in theory applying it at every passage of lists (building up before processing and passing on in each case) i should "trickle down" the most essential, but somehow manage to break it as soon as i try to apply it... going back in world now with a re-working that all llooks pretty much like this:

CODE


if(msg!="")
{


list r_data=llParseString2List(msg,["|"],[""]);
string rkey=llList2String(r_data,0);
integer check_list=llListFindList(biglist,[rkey]);

if (check_list == -1)
{
biglist += rkey;
veclist += llList2String(r_data,1);
}

CODE


which as soon as i'm sure it's working i will look to pack into all one string/strided list to reduce chatter.... but for now still banging on keyboard and grunting at it all.

P.S. Thank you, Q! i had looked at boolean and not bitwise for som reason. now i've gotten it, tried it and it's not what i need but finally an arcane rune revealed ;-)
Chrysala Desideri
Scarlet Scriptrix
Join date: 4 Mar 2007
Posts: 65
09-22-2007 08:27
Works fine, the above! I guess was another "crossyed-point" lockup...

and from the first look at the icons, i do believe it's working...
1 2