Jump to content
Edu Csak

Receive new channel and start listening to it

Recommended Posts

I've got  an item and a HUD 
The item says the HUD which channel to use, but I"m stucked on how it changes. It's keep on using the old channel setted.

The HUD uses channel 2 (for example)
Then the item says to HUD to use channel 9
It listens, but keeps on using channel 2, not 9

state_entry() { chan=2; }
listen(integer CHAN, string name, key id, string msg) { chan=(integer)msg;  } // msg = 9

What I'm missing?

Share this post


Link to post
Share on other sites
1 minute ago, Edu Csak said:

What I'm missing?

The entire remainder of your script, including any llListen statement that actually opens the listen handler so that the script can listen on that channel.  I suggest reading in the LSL wiki >>> http://wiki.secondlife.com/wiki/LlListen

  • Haha 1

Share this post


Link to post
Share on other sites
Posted (edited)

OK, but my issue is how to change the llsay to start saying on channel 9 and not on 2. 
Initially, the hud uses the channel 2. Then the item says to hud to use channel 9. But I cannot have it saying channel 9. keeps on llSay(ing) on channel 2

state_entry() { chan=2; }
listen(integer chan, string name, key id, string msg) {
    chan=(integer)msg;   // msg = 9 - script now must llSay on channel 9... not on 2 anymore

}
But the variable chan receives the new value on listen, but keeps on reapplying the 2 above

Edited by Edu Csak

Share this post


Link to post
Share on other sites

@Edu Csak

It would be immensely helpful if you posted your entire script. It's only going to be a guessing game about what to tell you until you help us help you.

Assuming that chan is a global variable, you just need to make sure llSay uses chan for its channel, and it should work.

Share this post


Link to post
Share on other sites

Because you have never opened the channel or, if you have, it's in parts of the script that you are not showing here.  You always need to provide an llListen handler to open a new channel.  If you don't want to run out of available channels, it's also good form to close a channel that you are no longer using.  Again, I suggest reading the examples in the LSL wiki.

Share this post


Link to post
Share on other sites

Finally, I made it work. Once the channel value was set on state_entry, I found out that there's no way to have it changed. So I made other variable to be used and resetted within llListen with the value I got from the listen and got it working on touch_start ;) Thank you all for your help

Share this post


Link to post
Share on other sites
Posted (edited)
5 hours ago, Edu Csak said:

Once the channel value was set on state_entry, I found out that there's no way to have it changed.

That's not quite the right lesson to take away from this, but I am glad that you got the script to work.  Now, let me show you an example of the sort of script that will do what you intended, even if it's not exactly what you had in mind .....

integer iChan;  // This is a global variable to store the channel number in
integer iLsn;   // This is a global variable assigned to hold the listen handler's id

default
{
    state_entry()
    {
          iChan = 4;
          iLsn = llListen(iChan,"","","");     // Here's a listen handler, initially assigned to iChan = 4
     }

     listen (integer channel, string name, key id, string message)
     {
          llSay(0, "This message was received on channel " + (string) iChan);
          iChan = (integer)llGetSubString(message,0,1);    // Grab the first two characters of the message, convert them to an integer, and assign to iChan
          message = llDeleteSubString(message,0,1);
          llSay(0,message);   // Say only the real text part of the message that was received.
          llListenRemove(iLsn);     // Remove the current listen handler so that the script won't listen on the old value of iChan
          iLsn = llListen(iChan,"","","");
     }
}

Put this simple script into the Contents of a brand new prim and play with it.  Send a message on channel 4 to start.  Your message should look something like:

35Here is my first message.

When the script hears that message, it should say: "This message was received on channel 4."  and then "Here is my first message."  Then send another message like the first, but this time on channel 35.  Each time you send a new message, the script will grab the first two characters of it and turn them into the number of a new channel.  (Edit:  A single digit channel should have a leading blank or zero, as in 06.) 

Now, if you want to learn to write scripts, play with this one and ask yourself questions like "What would happen if I typed something other than a number at the start of the message?  And how could I prevent that from happening?"

Edited by Rolig Loon
  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...