Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Working With Lists

Melo Chevalier
Registered User
Join date: 18 Sep 2008
Posts: 2
09-22-2008 03:40
Hi everyone, I'm learning how to script and now stuck with list. For example I get list like:

1, Avie Name, Avie Key
2, Avie Name, Avie Key
3, Avie Name, Avie Key

I want to give avie 1 6L$, avie 2 3L$, avie 3 1L$.

My script looks like this and it's not working. I don't know how to pay the other 2


myList = llCSV2List(strMessage);
length = llGetListLength(myList);


integer i;

for (i=0; i<length; ++i)
{
if(i == 3)
{
llGiveMoney(llList2String(myList, i), 6);
}
}

What it does is give 6L$ to all three. Please help. Thanks
Jodie Suisei
Lost In LSL Code
Join date: 6 Oct 2006
Posts: 66
09-22-2008 04:36
Not a massive experience scripter but i do see a few problems with your list.

Your assigning a name and a key into a list but i dont see any type casting of converting that listed key back into a key format, unless you have that hidden else where in the script that you havent posted.

as for a quick solution even though im not great at maths since the total you want to pay all three is 10 should be along the lines of 10 / 3 the single / is divide ;)

CODE


integer i;

for (i=0; i<length; ++i)
{
if(i == 3)
{
llGiveMoney(llList2String(myList, i), 10 / 3);
}
}


that should then give the first person 6 the second 3 then the last 1

Correct me if a more advanced scripter has a better solution or if im wrong lol
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
09-22-2008 04:45
Why not just put the amount into the list as well? Like this:

CODE
list recipients = [
name1, key1, 6,
name2, key2, 3,
name3, key3, 1
];

default {
some_event() {
integer l = recipients != [];
if (l <= 0) return;

integer i = 1; key id; integer amt;
do {
id = llList2Key(recipients, i);
amt = llList2Integer(recipients, ++i);

llGiveMoney(id, amt);
} while ((i += 2) < l);
}
}


Remember to swap some_event() for whatever you're interested in triggering!

If you're trying to make a vendor where people get a different share of money made, then you could change the integers to float values representing a percentage of the amount received in the money() event, and perform some calculation to figure out how much to give each person.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)