Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Change Channels

Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
05-03-2006 09:37
How can I make it so if an object is listening on Channel 1 and I say

"/1 Switch to Channel 2"

it then listens on Channel 2 from now on?
Androclese Antonelli
Org. B-Day: 05/11/04
Join date: 25 Apr 2006
Posts: 96
05-03-2006 10:01
To make it permenant for the object, regardless of whether or not it is in your inventory or newly rez'd, you would have to store the channel on a note card and then read/write to the card based on your "Switch to Channel" command.
_____________________
The Sculpted Garden

Originally Born 5/11/2004 - New AV, Old Player.

If you leave the game, don't delete your account, just make it 'free'. You'll lose your inventory like I did. *sniff*
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
05-03-2006 11:23
Any example code or links to some example code?
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
05-03-2006 11:25
But you cannot write to a notecard from a script. Instead, you could store such information in the object description, using llGetObjectDesc and llSetObjectDesc.

Baron
Neb Soyer
Really good looking.
Join date: 9 Apr 2006
Posts: 45
05-03-2006 11:43
From: Baron Hauptmann
But you cannot write to a notecard from a script. Instead, you could store such information in the object description, using llGetObjectDesc and llSetObjectDesc.

Baron


Yeah, Baron's right, I'm sure you could store it in lists too, but using llGetObjectDesc & llSetObjectDesc works just as well.

Compiled and tested:

CODE
string temp;

default
{
state_entry()
{
llListen((integer)llGetObjectDesc(), "", llGetOwner(), ""); //begins listen from number found within object desc
}

on_rez(integer num)
{
llSetObjectDesc((string)0); //sets desc to 0, so its listening on normal chat at first
llResetScript(); //reset to listen upon (new) owner
}

listen(integer channel, string name, key id, string message)
{
temp = llGetSubString(message,0,8);
if(temp == "/channel ")
{
temp = llGetSubString(message,9,-1);
llOwnerSay("Channel set: " + temp + "."); //say what you set it to
llSetObjectDesc(temp); //set desc to what you said
llResetScript(); //reset script, which then gets the desc again within state_entry
}
}
}


Oh yeah, to use;

Example: /channel 1

It would then only listen on channel 1, so only;

/1 /channel 0

Would get it back to normal chat again, or to another channel specified.
_____________________
down in the ghetto.
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
05-07-2006 10:56
I tested and works great, but when you have many objects it does not help when I say /1 change channel 2 and they ALL change to channel 2 LOL.

How can I put this so the channel is on a notecard? That would solve my problems. /laughs
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
05-07-2006 11:05
Rather than adding notecard functionality (which you don't need for something this simple), just set the object description to the desired channel you want, then reset the scripts in the object (or put in a reset command that calls llResetScript).

One problem with Neb's code if you want to take configured objects into inventory and rez them later with the changed channels, it will reset them to 0. If you don't need to do that, it's not a problem, of course. ;)
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
05-07-2006 11:10
From: Over Sleeper
How can I put this so the channel is on a notecard? That would solve my problems. /laughs

CODE

string channel_card_name = "comm_channel";
key channel_card = NULL_KEY;
integer command_channel = 0;

default {

state_entry() {

if( llGetInventoryType( channel_card_name ) == INVENTORY_NOTECARD ) {

channel_card = llGetNotecardLine( channel_card_name, 0 );
}
}

dataserver( key Id, string Data ) {

if( Id == channel_card ) {

channel_card = NULL_KEY;
if( Data != EOF ) {

command_channel = (integer)Data;
llOwnerSay( "the communication channel is now " + Data + "." );
llListen( command_channel, ... ); // set up listen filter as desired
}
}
}
}

this shall read card with name defined in channel_card_name and react accordingly when the result is received. Useful when you want to keep the item description clear for other purposes, i guess ^^;

edit: you'll probably want to remove the old listen filter if one is present, so might be nice to store handle to listen filter somewhere there.
Adriana Caligari
Registered User
Join date: 21 Apr 2005
Posts: 458
05-07-2006 11:38
From: Over Sleeper
I tested and works great, but when you have many objects it does not help when I say /1 change channel 2 and they ALL change to channel 2 LOL.

How can I put this so the channel is on a notecard? That would solve my problems. /laughs


Why not check for the object name - or place a "trigger" next to the channel in the description ?

Eg
Decsription reads : 1,shoe

Code to read description
CODE

list temp = llCSV2List( llGetObjectDesc() );
integer channel = (integer)llList2String( temp,0 ) ; // get the channel
string trigger = llList2String( temp,1 ) ; // get the chat "trigger"
integer old_listen = llListen( channel, "", llGetOwner(),"" );


Then in your listen

CODE

listen ( integer ch, string nm, key id, string mess )
{
list temp = llParseString2List( mess,[" "],[] );
string who = llList2String( temp,0 ) ; // get the name
string command = llList2String( temp,1 ) ; get the command
string parameter = llLIst2String( temp,2 ) ; get the parameter
//
if ( who != trigger ) {return;} // dont do anything - they didnt say the object trigger
//
if ( llToLower( command ) == "channel" )
{
new_channel = (integer)parameter;
llListenRemove( old_listen ) ;
old_listen = lllisten( new_channel,"",llGetOwner(),"" );
//
llsetObjectDesc ( (string)new_channel + "," + trigger ) ; // store the new channel
}
//
}


That way if oyu set the trigger to be shoe you have to say

/1 shoe channel 2

To change the shoe to channel 2 - if you say
/1 belt channel 2

It will be ignored.
Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
05-07-2006 11:47
What if the objects are named the same thing? Which they are.
This is why I need it ina notecard.