Jump to content

Receive new channel and start listening to it


Edu Csak
 Share

You are about to reply to a thread that has been inactive for 1452 days.

Please take a moment to consider if this thread is worth bumping.

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?

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1452 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...