Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Passing a list to another Prim?

Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
12-20-2008 07:47
is it possible to send a List to another prim?
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
12-20-2008 08:57
Yes, kind of. A common way to do it is to turn the list into a string. You can use llList2CSV or llDumpList2String to do it, and then send the string by link message, chat, email, or whatever else. You would then reconstruct the list at the other end using llCSV2List, llParseString2List, or llParseStringKeepNulls.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
12-20-2008 09:01
Yes. You just have to turn it into a string, using llDumpList2String(), send it to the receiver by llSay() or llMessageLinked(), and then use llParseString2List() to turn the message back into a list when it gets there. It'll all be in strings, then, of course, so at some point you need to reconvert them into whatever type they were in the first place.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llDumpList2String
http://www.lslwiki.net/lslwiki/wakka.php?wakka=llParseString2List

(and Pedro beat me to it with a fuller and better answer).
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
12-20-2008 09:52
Here's something I threw together...

Sender script
From: someone

list my_data;
integer communication_channel;
integer list_length;
integer call;

parse_incoming_data(string text) // parse incoming data
{
list messages = llParseString2List(text,["@"],[]);
string header = llList2String(messages,0);
string data = llList2String(messages,1);

if (header == "verify";) // verify list length with incoming number from receiving script to make sure all data arrived ok
{
if ((integer)data == list_length)
{
llOwnerSay("Data successfully transferred.";);
} else
{
llOwnerSay("Data not received successfully.";);
}
}

llListenRemove(call);
}

message(string text) // if more than one prim is detected the prim must be linked, else use chat
{
if (llGetNumberOfPrims() > 1)
{ llMessageLinked(LINK_ALL_OTHERS,0,text,NULL_KEY);}
else { llSay(communication_channel,text);}
}


defaults() // load defaults
{
communication_channel = -4; // chat channel (if not linked)
my_data = ["mydata1","mydata2","mydata3","mydata4"];
}

move_data() // sends data to receiving script via appropriate method
{
integer t;
list_length = llGetListLength(my_data);

if (list_length > 0)
{
for(t=0;t<list_length;++t)
{
message("custom_data_header@"+llList2String(my_data,t)); // send data with a header
}
}
}

default
{
state_entry()
{
defaults(); // load defaults
}

touch_start(integer total_number)
{
if (llGetNumberOfPrims() == 1) { call = llListen(communication_channel,"",NULL_KEY,"";);} // listen if not linked

llOwnerSay("Moving list data to destination.";);
message("clear_mydata@";); // tell the receiving script to clear its list
move_data(); // send data
message("end_of_data@";); // send end of data
}

listen(integer channel, string name, key id, string message)
{
parse_incoming_data(message); // parse received messages from chat channel
}

link_message(integer sender_num, integer num, string message, key id)
{
parse_incoming_data(message); // parse received messages from link messages
}
}


Receiver script
From: someone

list my_data; // stores the data
integer count; // counts the number of data lines received
integer communication_channel; // chat channel (if not linked)
integer call;

parse_incoming_data(string text) // parse incoming data from the sending script
{
list messages = llParseString2List(text,["@"],[]);
string header = llList2String(messages,0);
string data = llList2String(messages,1);

if (header == "clear_mydata";) // clear the list
{
count = 0;
my_data = [];
}

if (header == "custom_data_header";) // receive data
{
my_data += [data]; // store incoming data into the list
count++; // keep track of lines received
}

if (header == "end_of_data";) // receive end of data message
{
message("verify@"+(string)count); // send verify count to sending script
}
}

message(string text) // communicate with the other script
{
if (llGetNumberOfPrims() > 1)
{ llMessageLinked(LINK_ALL_OTHERS,0,text,NULL_KEY);}
else { llSay(communication_channel,text);}
}

defaults()
{
communication_channel = -4; // chat channel (if not linked)
count = 0; // data counter
my_data = []; // empty list
}

default
{
state_entry()
{
defaults();
if (llGetNumberOfPrims() == 1) { call = llListen(communication_channel,"",NULL_KEY,"";);} // listen if not linked
}

changed(integer change)
{
if (change & CHANGED_LINK) // linked or unlinked changed? listen if not linked
{
llListenRemove(call);
if (llGetNumberOfPrims() == 1) { call = llListen(communication_channel,"",NULL_KEY,"";);} // listen if not linked
}
}

listen(integer channel, string name, key id, string message)
{
parse_incoming_data(message); // parse incoming data
}

link_message(integer sender_num, integer num, string message, key id)
{
parse_incoming_data(message); // parse incoming data
}
}
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-20-2008 10:26
There's one thing to watch out for. If any of the list elements are strings and contain characters that could look like your list separators (vectors and rotations are fine, but arbitrary strings...), it could break them up into multiple elements when you parse the serialization again. If there's any chance of this, you might want to do something like a Base64 conversion of each element.