Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple List Script Wanted

Robertt Goodliffe
Registered User
Join date: 1 Jan 2006
Posts: 16
09-18-2006 05:51
Im trying to learn how to use lists but i will admit i find them confusing.

So I was hoping somebody might be able to script me a simple script that does the following so I can see how they work properly. The examples in the Wiki confuse the hell out of me.

The list needs to store the keys of the last 3 people to touch the prim its stored in.
It must also keep track of how many times that person has touched it.
When the person attempts to touch it a 3rd time the message 'keep your hands off me' is sent.
When a 4th person touches the object the 1st person who touched it is droped from the list.
The last 3 people to touch the prim and how many times they have touched it are displayed above prim using llSetText.

Thanking you,
Frosty Fox
Registered User
Join date: 28 Feb 2005
Posts: 18
09-18-2006 06:18
you'll have to play with somthing like this

CODE

list ppl;

integer av_num(key id)
{
integer pos = llListFindList(ppl,[id]);
return llList2Integer(ppl,pos+1);
}

update_av(key id,integer no)
{
integer pos = llListFindList(ppl,[id]);
ppl = llDeleteSubList(ppl,pos,pos+1);
ppl+=[id,no];
}

default
{
touch_start(integer total_number)
{
integer i;
while (i<total_number) // if more than 1 person touched it
{
key av = llDetectedKey(i);
integer pos = llListFindList(ppl,[av]);
if(pos==-1) // if not found
{
ppl+=[av,1];
llOwnerSay("Added "+(string)llKey2Name(av)+" to list");
}
else
{
if(av_num(av)>=3)
{
llOwnerSay("You have touched me 3 times");
}
else
{
llOwnerSay("av++");
update_av(av,av_num(av)+1);
}
}
++i;
}
}
}


to delete sombody from the beginnin you need to use
ppl = llDeleteSubList(ppl,pos,pos+1);
and a llGetListLength(pp) somewhere :)
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
09-18-2006 06:25
Here's one that I knocked up just now with text display and key + name + count storage in the list... it *should* work.
CODE
list gList = [];

default
{
state_entry()
{
llSetText("", ZERO_VECTOR, 0.0);
}

touch_start(integer n)
{
key id = llDetectedKey(0);
integer pos = llListFindList(gList, [id]);
if (pos == -1) {
// Not in list
gList += [id, llDetectedName(0), 1];
// Check whether list is too long now
if (llGetListLength(gList) > 9) {
// Remove first three list items
gList = llDeleteSubList(gList, 0, 2);
}
}
else {
// Already in list
integer touchCount = llList2Integer(gList, pos + 2) + 1;
// Check current touch count
if (touchCount > 3) {
llSay(0, "Hands off!");
}
else {
// Increment touch counter for that avatar in the list
gList = llListReplaceList(gList, [touchCount], pos + 2, pos + 2);
}
}
// Update text display
string msg = "";
integer f = 0;
do {
msg += llList2String(gList, f + 1) + ": " + llList2String(gList, f + 2) + "\n";
} while (f < llGetListLength(gList));
llSetText(msg, <1.0, 1.0, 1.0>, 1.0);
}
}
Keiki Lemieux
I make HUDDLES
Join date: 8 Jul 2005
Posts: 1,490
09-18-2006 07:40
And here is my version :p

CODE
// I'm going to use a strided list that keeps track of
// - the time they last touched it
// - avatar names
// - avatar keys
// - the number of times they have touched it.
list avatars = [];
integer STRIDE = 4;

// This is list of messages it displays when touched:
list messages = [ "/me giggles", "Hey now!", "That tickles, stop it!", "Keep your hands off of me!"];

Display_names() {
string touch_text = "The last avatar(s) to touch me were:";
string this_ava = "";
integer i = 0;
do {
this_ava = llList2String( avatars, i * STRIDE + 1 );
if ( this_ava != "" ) {
touch_text += "\n" + this_ava + " - " + llList2String( avatars, i * STRIDE + 3 ) + " times";
}
} while ( i++ < 3 );
llSetText( touch_text, <1.0,1.0,1.0>, 1.0 );
}


default {
state_entry() {
llSetText( "Never been touched!", <1.0,1.0,1.0>, 1.0 );
}

touch_start ( integer num_detected ) {
key this_key = llDetectedKey( 0 );
integer check = llListFindList( avatars, [ this_key ] );
integer count = 1;
if ( check != -1 ) {
count = llList2Integer( avatars, check + 1 ) + 1;
avatars = llListReplaceList( avatars, [ llGetUnixTime(), llDetectedName( 0 ), this_key, count ], check - 2, check + 1 );
}
else if ( llGetListLength( avatars ) < 12 ) {
avatars += [ llGetUnixTime(), llDetectedName( 0 ), this_key, count ];
}
else {
avatars = llListReplaceList( avatars, [ llGetUnixTime(), llDetectedName( 0 ), this_key, count ], 8, 11 );
}
avatars = llListSort( avatars, STRIDE, FALSE );
Display_names();
if ( count > 4 ) { count = 4; }
llSay( 0, llList2String( messages, count - 1 ) );
}
}
_____________________
imakehuddles.com/wordpress/