Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Attachment communication

DALEK Drillon
Registered User
Join date: 20 Jul 2006
Posts: 22
08-07-2008 02:52
Hi all fairly simple for some of you im guessing. I need to communicate some how between attachments but i dont know how to do this if theres 2 of the same products in the same area say for instance llSay distance they'll inter-mingle O.o because its not private. So im guessing i need some sort of private trick and thats why im asking :)

Any help would be great thanks for you time
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
08-07-2008 05:09
There are two ways:

1) Use Say, or Shout on a specific (not 0) channel: Object A Says. Object B listens on that channel for messages coming from the owner's objects

2) Use email to communicate between objects.
DALEK Drillon
Registered User
Join date: 20 Jul 2006
Posts: 22
08-07-2008 10:34
Thanks :)
DALEK Drillon
Registered User
Join date: 20 Jul 2006
Posts: 22
08-07-2008 11:40
From: Monica Balut
There are two ways:

1) Use Say, or Shout on a specific (not 0) channel: Object A Says. Object B listens on that channel for messages coming from the owner's objects

2) Use email to communicate between objects.




Is there anybody out there willing to show me an example of how 1) is done, seems a little fidgetty.
any help greatly appreciated :)
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-07-2008 11:42
I think this may need some clarification. Do you mean you want to communicate between different attachments on the SAME avatar, and ignore messages sent by attachments on OTHER avatars? If so, llWhisper() should be more than sufficient, and you can filter out messages from other avatars' attachments by testing llGetOwnerKey() of the speaking object in your 'listen' handler, since an object MUST be owned by the resident whose avatar it is attached to. For example:

CODE

integer CHANNEL = -1723111205;

default
{
state_entry()
{
llListen(CHANNEL, "", NULL_KEY, "");
}

touch_start(integer nDetected)
{
key owner = llGetOwner();

integer i;
for (i = 0; i < nDetected; ++i)
{
if (llDetectedKey(i) == owner)
{
integer attachPos = llGetAttached();
if (attachPos)
{
llWhisper(CHANNEL, "attached to position"+(string)attachPos);
} else
{
llWhisper(CHANNEL, "not attached to avatar");
}
}
}
}

listen(integer channel, string name, key id, string message)
{
if (llGetOwnerKey(id) != llGetOwner())
{
// Owned by (attached to) different avatar
return;
}

llOwnerSay("Heard from object "+message);
}
}


Another option is to calculate a channel number using something owner-specific, such as their key. Use a hash function of some sort to make it unlikely the channel will be the same for any two avatars (not SO important if you're using the avatar's UUID like here since that is pretty random already, but could also be used for names or whatever; besides, it conveniently removes the dashes):

CODE

integer channel;

integer keyToNegativeChannel(key id)
{
string hash = llMD5String((string)id);

string num1 = (integer)("0x"+llGetSubString(hash, 0, 7));
string num2 = (integer)("0x"+llGetSubString(hash, 8, 15));
string num3 = (integer)("0x"+llGetSubString(hash, 16, 23));
string num4 = (integer)("0x"+llGetSubString(hash, 24, 31));

// Ensure it is negative
return 0x80000000 | (num1 ^ num2 ^ num3 ^ num4);
}

default
{
state_entry()
{
channel = keyToNegativeChannel(llGetOwner());
llListen(channel, "", NULL_KEY, "");
}

touch_start(integer nDetected)
{
key owner = llGetOwner();

integer i;
for (i = 0; i < nDetected; ++i)
{
if (llDetectedKey(i) == owner)
{
integer attachPos = llGetAttached();
if (attachPos)
{
llWhisper(channel, "attached to position"+(string)attachPos);
} else
{
llWhisper(channel, "not attached to avatar");
}
}
}
}

listen(integer channel, string name, key id, string message)
{
// Unlikely this message is from another resident's object, though you
// COULD still check here to be sure.

llOwnerSay("Heard from object "+message);
}
}


I didn't handle changes in ownership because these are simple illustration scripts. For the first you'd have to restart the listen, obviously. For the second you'd also have to recalculate the channel number first.
DALEK Drillon
Registered User
Join date: 20 Jul 2006
Posts: 22
08-07-2008 12:05
Thanks Hewee thats just brilliant!.