Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Attached object communication

Amy Burton
Registered User
Join date: 14 Dec 2006
Posts: 16
07-01-2007 18:40
Hi!

Is there any way for scripted objects attached to different parts of the body to communicate with eachother without llListen, llEmail or http? :)

Im trying to use a HUD to communicate with my hat! Just testing, want it to change colours :p but I don't want to use listens because it'll probably change everyone else's hat around me... llEmail is too slow, and I really wish to avoid http :P

Thanks in advance!

-Amy
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-01-2007 19:22
I think llListen() is the easiest, but the communications would need to be tagged according to owner. In its simplest form, this would "wake up" everybody else's hats long enough to determine that the message isn't for them, but at least they'll know better than to respond to commands from an object other than their owner's. And if there's gonna be a whole lot of comms, then once the HUD and the hat are "introduced" one of them can send a random private channel for them to exhange whatever hats and HUDs share on their heart-to-hearts.

For that matter, it may be worth thinking about having the hat rez the HUD, passing the private channel in the rezzing event. This also has the advantage of not being subject to spoofing by "hostile hat HUDs" who might know the owner's key. But even in a benigh hat environment, it may actually be more convenient if the HUD just popped up (after approval to attach) whenever one wears the hat.
Amy Burton
Registered User
Join date: 14 Dec 2006
Posts: 16
07-01-2007 19:56
Thanks.

So the best way is to use listens, but on_rez event (log in or teleport) i'll have both scripts reset themselves to the default channel, then the Hat would llRound(llFrand(#)); a channel number and whisper the new channel in the default channel. Then the HUD script will recognise the new channel and use that instead. I guess it's safer to use negative channels too. Alternatively, I guess it would be safer to have a touch event on the hat to send the new channel incase the HUD script doesn't get the new channel...

Or a button on the HUD that communicates the new channel to the hat.

I'll have a go at this ;)

Thanks again!

-Amy
Cortex Draper
Registered User
Join date: 23 Aug 2005
Posts: 406
07-03-2007 03:33
Remember in the listen event to check that the owner of the saying object is the same as the owner of your listening object.
This will make sure your hud only talks to your hat not nearby peoples hats.

listen(integer n, string name, key id, string msg)
{
if(llGetOwnerKey(id) == owner)
{//Only triggers if what spoke is the owner or if they share the same owner

}
}
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-03-2007 08:49
You could also factor in the owner's key to select a more unique channel, then you won't have to filter out so much crosstalk.

Something like this would make all your scripts select the same (rather unique) channel for each owner:

integer CHANNELBASE = -555;
integer my_channel = (integer)("0x" + (string)llGetOwner()) ^ CHANNELBASE;

Then you listen on my_channel for all your devices.

Note: Be sure to check for new ownership on_rez of course. It makes for a bit of extra code, but will run more efficiently than having all owner's objects waking up when one of them speaks on a universally-used channel.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
07-05-2007 07:04
From: Boss Spectre
You could also factor in the owner's key to select a more unique channel, then you won't have to filter out so much crosstalk.

Something like this would make all your scripts select the same (rather unique) channel for each owner:

integer CHANNELBASE = -555;
integer my_channel = (integer)("0x" + (string)llGetOwner()) ^ CHANNELBASE;

Then you listen on my_channel for all your devices.

Note: Be sure to check for new ownership on_rez of course. It makes for a bit of extra code, but will run more efficiently than having all owner's objects waking up when one of them speaks on a universally-used channel.


that's an interesting way of going about things. If I'm reading this correctly, it's creating a hexidecimal number with the "0x" + llGetOwner(). Then it does some kind of bitwise operation (don't know exactly what XOR is/means).

Can this produce a number higher than the max channel number? some of my tests have numbers that are very close
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-05-2007 07:30
From: Senuka Harbinger
that's an interesting way of going about things. If I'm reading this correctly, it's creating a hexidecimal number with the "0x" + llGetOwner(). Then it does some kind of bitwise operation (don't know exactly what XOR is/means).

Can this produce a number higher than the max channel number? some of my tests have numbers that are very close


"XOR" means "exclusive or"... so 1^1=0, 1^0=1, 0^1=1, 0^0=0.
The (integer) typecast forces the result into integer range, all of which is valid for channels.