Random Chat Channels on Rez
|
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
|
09-13-2009 07:50
I've seen some discussion on this topic but I have not been able to find an example. When creating two unlinked objects that need to communicate via chat, we want to have them set up on a random chat channel to avoid cross talk with another pair of these same objects the same owner has nearby. So we want to have them both start on say channel -3493 for example and one generates a random channel # and passes to the other to use for any further communications. This makes sense? I seem to have gotten in to quite a mess of spaghetti code trying to do this simple task. Does anyone know of an example that is posted somewhere or do you have a snippet of code to share?
Thanks in advance!
|
Indeterminate Schism
Registered User
Join date: 24 May 2008
Posts: 236
|
09-13-2009 09:30
The usual way you'd do this is by having one object generate the random channel number, rez it's "twin" and pass the channel as the last argument of the llRezObject() function: llRezObject( string inventory, vector pos, vector vel, rotation rot, integer param ); In the on_rez() event this is received as the Start Parameter: on_rez( integer start_param ). If rezzed from inventory this will be 0 so you can use the same script in both objects and just check whether this is the original or the twin based on the start parameter. This should give you the idea (typed 'freehand' so don't cut & paste) integer ChatChannel; on_rez(integer start_param) { if (start_param == 0) { // This is the original so generate the channel and rez a twin ChatChannel = -(integer) (llFrand(10000.0) + 1); llRezObject("My Twin", llGetPos() + <0.0,0.0,1.0>, <0.0,0.0,0.0>, <0.0,0.0,0.0,1.0>, ChatChannel); } else { // The twin, so use what's given ChatChannel = start_param; } llListen(ChatChannel, "My Twin", NULL_KEY, ""  ; } It's a bit more difficult if you want to rez two identical things and get them to 'pair up' as there has to be a way to determine which goes first.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-13-2009 09:32
From: Fillo Farber I've seen some discussion on this topic but I have not been able to find an example. When creating two unlinked objects that need to communicate via chat, we want to have them set up on a random chat channel to avoid cross talk with another pair of these same objects the same owner has nearby. So we want to have them both start on say channel -3493 for example and one generates a random channel # and passes to the other to use for any further communications. This makes sense? I seem to have gotten in to quite a mess of spaghetti code trying to do this simple task. Does anyone know of an example that is posted somewhere or do you have a snippet of code to share?
Thanks in advance! The final parameter in the llRezObject function and the only parameter in the on_rez event are the same. You can pass an integer from the rezzing object to the newly-rezzed object in that parameter. All you have to do is create your channel number in the rezzing program, stuff it in the llRezObject function, and read it out as the new one is created. Piece of cake. ETA: What he said....... 
_____________________
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 
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-13-2009 09:42
Try this little script. Put a copy in each prim, take them and rez them, then touch ech prim to test the channel number. // symmetric random channel setup for two rezzed prims // includes channel test // this script goes in each prim
integer baseHandle; integer baseChannel = -3493; integer handle; integer channel = -10;
default { on_rez( integer p ) { llListenRemove( handle ); llListenRemove( baseHandle ); baseHandle = llListen( baseChannel, "", NULL_KEY, ""); channel = (integer)llFrand( 8388608.0 ) + 0x80000000; handle = llListen( channel, "", NULL_KEY, ""); llRegionSay( baseChannel, (string)channel); }
listen(integer kanal, string name, key id, string message) { llListenRemove( baseHandle ); if ( kanal == baseChannel ) { channel = (integer)message; llListenRemove( handle ); handle = llListen( channel, "", NULL_KEY, ""); } else llOwnerSay( name+" talks on channel: "+(string)kanal ); // for testing }
touch_end(integer n) { llRegionSay( channel, "Channel test" ); // for testing } }
Remember to name the prims differently, otherwise the test don't make sense. The program is compiled and tested. It is in good working condition  You have to adopt the scripts to your personal needs. You may use stronger filters including name and/or message. Note: the two prims are rezzed independently. I understood that was what was wanted and not one prim rezzing the other. Happy scripting 
_____________________
From Studio Dora
|
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
|
09-13-2009 09:49
From: Indeterminate Schism It's a bit more difficult if you want to rez two identical things and get them to 'pair up' as there has to be a way to determine which goes first.
Yes. I was working to have the two objects rez independently and "pair up" as you say. One method was to have one repeat a "GO" msg every X seconds on a predetermined channel until the other replied. Then set a new random channel- after which they would ignore that first channel. But as I said - I ended up with a bunch of confusing spaghetti code before I finished. For simplicity, I may just go the way of rezzing the second object from the first as you both indicated. There is no reason for this not to work that way. It would be interesting to see what someone comes up with for the "pair up" method. If anyone has anything on that, please feel free to post your ideas. Thanks for the comments!
|
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
|
09-13-2009 10:02
From: Fillo Farber It would be interesting to see what someone comes up with for the "pair up" method. Though I'm prone to jumping into these threads without understading what I'm talking about, I'll offer my two thoughts anyway. 1) Include a timestamp from llGetTimestamp, which returns a result with sub-second precision (if not accuracy), as part of the message that establishes the random channel. 2) Have a third object act as referee.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-13-2009 11:01
I guess I still don't see what the challenge is. You have one parent object that can rez as many children as you want. It creates a random channel number and sends it to Child #1 through the on_rez event. Then it creates Child #2 the same way, passing it the same channel number. Bingo. Child #1 speaks and Child #2 listens, and vice versa. If you don't want the parent to hear what the children are talking about, tell it to llListenRemove its random channel handle. If you don't like to keep the parent around after the children are rezzed, kill it. Did I miss something?
_____________________
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 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-13-2009 11:12
If the idea is to create the two new objects from separate parents, then the answer is still easy. Name Object #1 something odd like "BillyBob_the _First" and name Object #2 "BillyBob_the_Second". In each object, open a temporary channel that they both know ---->> llListen(-5791035,"BillyBob_the_First",llGetOwnerKey(llGetKey()),"Hi Bob!"  . Put an llSay(-5791035,"Hi Bob!"  statement in a timer event in each new object and tell it to speak periodically until it gets an answer. Then have one object generate a new random channel number and send it to the other one. From then on, they talk to each other, and NOBODY else knows their private channel. That's the method you already thought of and Dora wrote out, but it doesn't involve any spaghetti. Should be a snap to script.
_____________________
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 
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-13-2009 11:33
From: Rolig Loon That's the method you already thought of and Dora wrote out Not exactly  my script doesn't rely on a specific object name and it certainly do not use any timer. Both objects/scripts start with a common base channel, that is all.
_____________________
From Studio Dora
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-13-2009 12:46
From: Dora Gustafson Not exactly  my script doesn't rely on a specific object name and it certainly do not use any timer. Both objects/scripts start with a common base channel, that is all. True, but that's the only vital part of the process. Two secret agents meet briefly, exchange bland hellos, agree on a secret code for later conversations, and disappear back into the crowd. Everything else -- timers, details of the llListen filters, etc -- is fluff around the edges of the process.
_____________________
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 
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
09-13-2009 13:48
From: Rolig Loon True, but that's the only vital part of the process. Two secret agents meet briefly, exchange bland hellos, agree on a secret code for later conversations, and disappear back into the crowd. Everything else -- timers, details of the llListen filters, etc -- is fluff around the edges of the process. You sure can make scripting seem a hell of a lot more exciting then it really is 
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
Vladimir Petrichor
Registered User
Join date: 6 Apr 2006
Posts: 19
|
09-13-2009 13:53
I believe what you are looking for is something like this... http://vladwerkz.wikidot.com/changing-dynamic-channel-encryptionYou are free to use it, as I keep it posted on my wiki for exactly that reason. It would be nice to receive credit if you do, though its not a big deal since most people aren't going to be looking inside your script anyway.
|
Delande Parx
Domesticated Panda owner
Join date: 21 May 2009
Posts: 5
|
09-16-2009 05:13
integer iSetupChannel = -165; integer iSetupHandler; integer iRandomChannel; integer iRandomHandler; default { state_entry() { } on_rez(integer start_param) { llListenRemove(iSetupHandler); llListenRemove(iRandomHandler); iSetupHandler = llListen(iSetupChannel, "", "", ""  ; iRandomChannel = -(integer) (llFrand(1000000) + 1); iRandomHandler = llListen(iRandomChannel, "", "", ""  ; llRegionSay(iSetupChannel, "SWITCHTO " + (string) iRandomChannel); } listen(integer channel, string name, key id, string message) { if (channel == iSetupChannel) { list iMessage = llParseString2List(message, [" "],[]); if (llList2String(iMessage, 0) == "SWITCHTO"  { iRandomChannel = llList2Integer(iMessage, 1); llListenRemove(iRandomHandler); llListenRemove(iSetupHandler); llRegionSay(iRandomChannel, "SWITCHED"  ; state state_switched; } } else if (channel == iRandomChannel) { if (message == "SWITCHED"  { llListenRemove(iSetupHandler); state state_switched; } } } } state state_switched { state_entry() { llOwnerSay("Paired up with another object on channel " + (string) iRandomChannel + "."  ; // Paired up with another object, state switched so you can start doing your stuff iRandomHandler = llListen(iRandomChannel, "", "", ""  ; } listen(integer channel, string name, key id, string message) { if (channel == iRandomChannel) { // Whatever you do here ... } } } Damn these forums suck with the lack of proper bbcode. Anyway, the above code works, though these crappy forums ate up all the formatting. Contact me in world if you want a formatted version of the above (or do it yourself, it's simple). It simply pairs up two objects whenever it can, then switches to a new state where you can do your normal script stuff. Pretty straight forward and simple. You can add an "alive" check to keep track of if your objects are still paired up and return to the previous state, etc. Easiest way to do that is to move the "on_rez" code to state_entry, and in the on_rez do a script reset instead, though that will make you lose your stored variable data of course.
_____________________
Domesticated Panda mainstore  Domesticated Panda xstreet listing 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-16-2009 06:19
To post a formatted script in the forum, put it between tags. All indenting will be preserved. Just be sure to leave a space after every "< " symbol. If you don't, you will get a 404 error when you try to 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 
|
Delande Parx
Domesticated Panda owner
Join date: 21 May 2009
Posts: 5
|
09-16-2009 07:12
Doesn't seem to work. I know it should be in vb, but that also doesn't work. Just like doesn't work. They just took out all the useful vbcode.
_____________________
Domesticated Panda mainstore  Domesticated Panda xstreet listing 
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
09-16-2009 07:14
To get the formatted code you can also press the "Quote" button within the contribution 
_____________________
From Studio Dora
|
Delande Parx
Domesticated Panda owner
Join date: 21 May 2009
Posts: 5
|
09-16-2009 08:53
Ah yes, that's true, can use the quote option as well  Still would love for LL to fix the vbcode though ...
_____________________
Domesticated Panda mainstore  Domesticated Panda xstreet listing 
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
09-16-2009 11:21
There's no snow in the forecast for Hell yet. 
_____________________
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 
|
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
|
09-16-2009 16:14
Thanks everyone for the input. I appreciate your views and help very much.
|
Tabris Daxter
Snake oil Salesman
Join date: 22 Feb 2009
Posts: 61
|
09-16-2009 18:11
this is what i use. it's a bit convoluted but it works. BEFORE YOU CRUCIFY ME I KNOW I'M A DIRTY CODER. there is a crap load of debug code in there but the basic outline is, Owner Key x (Owner Key + Owner Name ) x -1 = chan integer dialog_channel1; integer dialog_channel2; integer dialog_channel3; key Key_ID; key ID = Key_ID; string name;
integer channel() { // top of script in functions //Gets Owner Key as integer return (integer)("0x"+llGetSubString((string)llGetOwnerKey(Key_ID),-16,-1)) ; }
integer channel2() { // top of script in functions //Gets HASH of Owner Key and Owner Name as integer return (integer)("0x"+llGetSubString((string)llSHA1String ( Key_ID + name),-16,-1)) ; }
default {
state_entry() { { llListen(dialog_channel3,"",llGetOwner(),""); Key_ID = llGetOwnerKey(ID); name = llKey2Name(Key_ID); dialog_channel1 = channel(); dialog_channel2 = channel2(); dialog_channel3 = (dialog_channel2 * dialog_channel1) * -1; llSay(0,"chan " + (string)dialog_channel3);
} } on_rez(integer start_param) { llResetScript(); } listen(integer channelabc, string nameabc, key idabc, string msg) { ParseAndIssueCommand(msg); //} //{ //Private Channel Code //Key_ID = llGetOwnerKey(ID); //name = llKey2Name(Key_ID); //dialog_channel1 = channel(); //dialog_channel2 = channel2(); //dialog_channel3 = (dialog_channel2 * dialog_channel1) * -1; //Listen //llListen(dialog_channel3,"","",""); // Here Down is Self explanitory. llSay(0, "Hello, " + name);
} //touch_start(integer total_number) //{ // llSay(0,"chan " + (string)dialog_channel3); //} }
_____________________
DANCE WITH KIRBY (^'-')^ (^'-')> (>'-')> <  '-'^) ^('-'^) (^'-')^ (^'-')> (>'-')> <  '-'^) ^('-'^)
|