Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A simple question about variables, please help

Netherene Velinov
Registered User
Join date: 9 Jan 2009
Posts: 2
01-25-2009 21:44
Hello i have 2 objects that need to exchange data between eachother except i dont know how to read data from scripts in diffrent objects from a diffrent object.

I'm making a combat system and I need one object to be worn that has the character's generel data and character creation. and the hud will have the other data such as the target and what spells you learn and ect.

How would I get the hud to read and change the data in the object that has the character data in it? and vice versa?

I don't see any tutorials specifically about this and I don't want to read a whole tutorial just to figure something simple as this out. Thanks in advance.
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-25-2009 21:53
llSay(channel, "string";); to tell the data.

and

llListen(channel, "","","";) is the funktion and
listen(integer channel, string name, key id, string message) is the triggered event to recieve data.

and i guess you need some typecasting when parsing the data.

float data = (float)message for example

http://wiki.secondlife.com/wiki/Category:LSL_Communications
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
01-25-2009 21:54
There's no real way to get two scripts to communicate directly, or share data. Most people just use llSay/llListen on a channel other than Channel 0 to pass data back and forth. It's inconvenient, but it works.
_____________________
Yingzi Xue
Registered User
Join date: 11 Jun 2008
Posts: 144
01-26-2009 08:56
To further iterate on the subject, this is a sample script I wrote up. The data exchange is overly simplified, but it should give you an idea what you can do with script communication. If you place this script in two objects (name them each differently), they'll each receive data every 5 seconds. The data is static in this example, but it should (hopefully) give you what you need to move forward with your project. :) I like to set up a routine in scripts that communicate that lets you easily switch between link communication or chat channel communication and distance. It makes it simple to adapt to whatever communication you need. One thing to keep in mind is that scripts can't hear their own chat messages, but they can hear link messages if you use LINK_SET in the llMessageLinked function.

CODE

integer configured; // Is the script configured?
integer listen_call; // Stores the llListen call number.
integer channel; // The communication channel.
integer comm_distance; // Distance to communicate, or linked if -1; see below.

// A place to store incoming data; overly simplified.
// Chances are you'll want to use lists for incoming data.
string data_type;
integer percentage;
integer price;

defaults()
{
channel = -80; // Set the communication channel; always use a negative channel for script comms.
comm_distance = 2; // -1=linked, 0=whisper (10m), 1=say (20m), 2=shout (100m), 3=regionsay (65535m)
price = 500;
percentage = 100;
configured = TRUE;
}

send_data(string text)
{
if (comm_distance == -1)
{
if (llGetNumberOfPrims() > 1)
{
llMessageLinked(LINK_SET,0,text,NULL_KEY);
} else { llInstantMessage(llGetOwner(),"The script is set to send link messages, but the prim isn't linked to anything.");}
} else if (comm_distance == 0)
{
llWhisper(channel,text);
} else if (comm_distance == 1)
{
llSay(channel,text);
} else if (comm_distance == 2)
{
llShout(channel,text);
} else if (comm_distance == 3)
{
llRegionSay(channel,text);
}
}

default
{
state_entry()
{
if (configured == FALSE)
{
defaults();
}

// Set listen for messages on channel. Use an object key in place of NULL_KEY to only listen to a particular object
listen_call = llListen(channel,"",NULL_KEY,"");

llSetTimerEvent(5); // send data every 5 seconds
}

timer()
{
// Send data; overly simplified. Comma used as data separator.
// Chances are data will be coming from script variables, not preset text.
send_data("numeric_data,price,"+(string)price);
send_data("numeric_data,percentage,"+(string)percentage);
}

listen(integer ch, string name, key id, string message)
{
list temp_list = llParseString2List(message,[","],[]); // parse message using comma separator
string name = llList2String(temp_list,0); // name = first list element
string data_type = llList2String(temp_list,1); // value = second list element
integer value = (integer)llList2String(temp_list,2); // and so on

if (name == "numeric_data")
{
// Process data; overly simplified.
if (data_type == "percentage")
{
if (value > -1)
{
llSay(0,"Received percentage value of "+(string)percentage);
percentage = value;
}
}

if (data_type == "price")
{
if (value > -1)
{
llSay(0,"Received price value of "+(string)price);
price = value;
}
}
}
}
}