Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script channel set using a Notecard

Shaden Sura
Registered User
Join date: 10 Oct 2006
Posts: 68
09-10-2007 00:08
Hi can some1 help me I am trying to make a Script that use a notecard for set and change the listen chennel /# can some help me with that thx for anyhelp u can gimme.
Auron Reardon
Registered User
Join date: 30 Jun 2006
Posts: 41
09-10-2007 05:02
Put the value you want in a notecard. Put the notecard in your object's inventory. Use llGetNotecardLine and the dataserver event to retrieve the value.

CODE

key kQuery;
integer nListenHandle;

state_entry()
{
//request the first line from the notecard...
kQuery = llGetNotecardLine("my notecard",0);
}

dataserver(key query_id, string data)
{
if (query_id == kQuery)
{
nListenHandle = llListen((string)data, "", NULL_KEY, "");
}
}


sorry - not sure how the code block tags are supposed to work...
Auron Reardon
Registered User
Join date: 30 Jun 2006
Posts: 41
09-10-2007 05:03
oops, change the typecasting from (string) to (integer):

Use this:

nListenHandle = llListen((integer)data, "", NULL_KEY, "";);

Not this:

nListenHandle = llListen((string)data, "", NULL_KEY, "";);
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
09-10-2007 07:14
You'll also want to make sure you get rid of any "old listen" that is in the script. That way, a customer can change the listen from channel 3 to 4 to 5 and not have it listening on all three:

if (query_id == kQuery)
{
llListenRemove(nListenHandle);
nListenHandle = llListen((string)data, "", NULL_KEY, "";);
}


Of course, if the channel selection runs only in state_entry (like it is in the example), then such a thing isn't really necessary.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Shaden Sura
Registered User
Join date: 10 Oct 2006
Posts: 68
09-10-2007 13:01
> .< I cant make it work this is the script I am trying to mod and put the change channel from nodecard

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

listen(integer channel, string name, key id, string message) {
if (message == "1";) {
llSetColor( <1.0,0.5,0.8>, ALL_SIDES );
llSay(0, "pink";);
}

if (message == "2";) {
llSetColor(<0.2, 0.0, 0.8>, ALL_SIDES);
llSay(0, "blue";);
}
}
}
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
09-10-2007 13:58
With the information in the previous posts, you should be able to make it work very easily. Here's a step-by-step:

CODE


integer handle;

string note;

key query;

init()
{
note = llGetInventoryName(INVENTORY_NOTECARD,0);
query = llGetNotecardLine(note, 0);
}

default
{
state_entry()
{
init();
}
changed(integer change)
{
if(change & CHANGED_INVENTORY) init();
}

listen(integer channel, string name, key id, string message) {
if (message == "1") {
llSetColor( <1.0,0.5,0.8>, ALL_SIDES );
llSay(0, "pink");
}

if (message == "2") {
llSetColor(<0.2, 0.0, 0.8>, ALL_SIDES);
llSay(0, "blue");
}
}

dataserver(key id, string data)
{
if(query != id) return;
if(data == EOF) return;
llListenRemove(handle);
handle = llListen((integer)data, "", NULL_KEY, "");
llOwnerSay("Now listening to channel: " + data);
}
}
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Shaden Sura
Registered User
Join date: 10 Oct 2006
Posts: 68
09-10-2007 15:11
Thx a lot ^^ for the help guys I realy thank u I am noob in scripting X3, the script work perfect