Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Setting a listen channel from a notecard

Sam Brewster
Registered User
Join date: 20 Feb 2006
Posts: 82
07-25-2006 22:02
I'm trying to set a listen channel from a notecard, but I'm having trouble getting it to work.

the notecard is one line with a number that I want to set the Listen channel to.

CODE

17


This is the script:
CODE

integer channel; // not assigning this variable set it to 0
string gName = "New Note"; // notecard line 1 is 17, so we should be listening to channel 12
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries

default
{

state_entry()
{
gQueryID = llGetNotecardLine(gName, gLine); // request first line
llListen(channel, "", NULL_KEY, "");
llSay(0, "state_entry channel set to " + (string)channel);
}

listen(integer channel, string name, key id, string message)
{
llSay(0, "Button Pushed");
}
dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF) // not at the end of the notecard
{
channel = (integer)data;
llSay(0, "Channel should be set to " + data);
llSay(0, "Now the script is listening to channel " + (string)channel);
}
}
}

touch_start(integer num)

{
llDialog(llDetectedKey(0), "test script", ["test"], channel);
}

}



The output from the script on reset is:

CODE

Object: state_entry channel set to 0
Object: Channel should be set to 17
Object: Now the script is listening to channel 17


and touching the menu button yields no result

But, if I edit the line in the notecard to be "0",

the script runs correctly:

CODE

Object: state_entry channel set to 0
Object: Channel should be set to 0
Object: Now the script is listening to channel 0
You: test
Object: Button Pushed
which is correct.

Can someone point me in the right direction, so that I can set the listen channel from a notecard?

Thanks,

Sam
Russell Hansen
Texi pets are here!
Join date: 11 Apr 2006
Posts: 107
07-25-2006 22:08
The llListen(channel, "", NULL_KEY, "");
should be put into your dataserver event after you set the channel variable (ie after the line channel = (integer)data;)

Where you have it at the moment, it is listening to channel 0.
Sam Brewster
Registered User
Join date: 20 Feb 2006
Posts: 82
07-25-2006 22:23
Thanks, Russel. I knew it had to be something simple, just couldn't wrap my mind around it. This is my first script that reads data off a notecard.


Regards,

Sam
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
07-26-2006 01:20
Remember to llListenRemove your old listener.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
07-26-2006 05:18
Ever since someone let me know about the llListenControl function, I don't think I'll ever use llListen again if I can help it.
Sam Brewster
Registered User
Join date: 20 Feb 2006
Posts: 82
07-26-2006 08:12
From: Tiarnalalon Sismondi
Ever since someone let me know about the llListenControl function, I don't think I'll ever use llListen again if I can help it.


After looking into llListenControl, I've started editing all my scripts with listens to use the control. Great tip. Thanks.

Sam