Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

List table manipulation

Debra Himmel
Registered User
Join date: 14 Jun 2008
Posts: 226
02-07-2010 05:44
Hi,

I would like to do the following but cannot figure out how:

I have a table in a list. The table would be like this:

name, time1, time2
name, time1, time2
name, time1, time2
name, time1, time2
name, time1, time2
name, time1, time2

What I need to know is how to read any cell in the table, or write to any cell in the table just like you can with an array.

If anyone can help me out with this, thanks in advance.
_____________________
OMG Katheryne uses Quackwatch.com for her research. OMG OMG. I kid you not. :eek:
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
02-07-2010 06:12
Hi Debra, the simplest method would be to use 3 lists, one for the names one for time1 and the last for time2.

But you can also use just one list and use something like this:

CODE

list mylist ;
float time1 ;
float time2 ;
string name ;
integer LIST_WIDTH = 3 ; // 3 elements per row : name, time1 and time2


getRow(integer num_row)
{
integer n = num_row * LIST_WIDTH ;
if (n < (llGetListLength(mylist) - LIST_WIDTH+1))
{
name = llList2String(mylist, n) ;
time1 = llList2Float(mylist, n+1) ;
time2 = llList2Float(mylist, n+2) ;
}
else
llOwnerSay("Error: list doesn't contain that many elements") ;

}

setRow(integer num_row, string n, float t1, float t2)
{
if (llGetListLength(mylist) < (num_row * LIST_WIDTH))
{
// We could give an error here or expand the list: let's expand it
integer diff = (llGetListLength(mylist) - (num_row * LIST_WIDTH)) / LIST_WIDTH ;
integer i ;
for (i=0; i< diff; i++)
{
if (i == (diff-1))
{
mylist += n ;
mylist+= t1 ;
mylist += t2 ;
}
else
{
mylist += "" ; // empty string
mylist += 0.0 ;
mylist += 0.0 ;
}
}
}
else
{
mylist = llListReplaceList(mylist, [ n, t1, t2], num_row*LIST_WIDTH, num_row*(LIST_WIDTH+1)-1) ;
}
}
default
{
state_entry()
{
integer i ;

// Initialize the list
for (i=0; i < 3; i++)
{
time1 = llGetTime() ;
time2 = time1 + 10;
name = "name " + (string)i ;
mylist += [name, time1, time2] ;
}
}

touch_start(integer total_number)
{
// get second row :
getRow(1) ; // 0 is first row, 1 second row and so on
llOwnerSay("name="+name+", time1="+(string)time1+", time2="+(string)time2) ;
setRow(1, "Hello", 10.0, 55.0) ;
getRow(1) ; // 0 is first row, 1 second row and so on
llOwnerSay("name="+name+", time1="+(string)time1+", time2="+(string)time2) ;


}
}


Not really tested but that should get you started.
_____________________
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
02-07-2010 06:13
LSL doesn't support arrays, but you can fake them with strided lists. Take a look at http://wiki.secondlife.com/wiki/Category:LSL_List for a good discussion of how it works. In practice, many scripters actually avoid strided lists and simply use sets of indexed lists to do the same thing. You'll find discussions of that approach at the same place on the LSL wiki.

ETA: Ah, and now you have an example, posted as I was typing this post. ;)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
02-07-2010 06:25
The getter was wrong, make sure you test everything before using that...
_____________________
Debra Himmel
Registered User
Join date: 14 Jun 2008
Posts: 226
02-07-2010 06:43
Ok, thank you. I will go throughout it.
_____________________
OMG Katheryne uses Quackwatch.com for her research. OMG OMG. I kid you not. :eek: