lang="en-US"> Second Life Tutorial: Communication Between Two Different Objects –  Design1online.com, LLC

Second Life Tutorial: Communication Between Two Different Objects

Finished Lego HouseFor my summer science research project I needed to build a lego house that would interact with a controller mounted on a working elevator. In order to get the controller communicating with the blocks I had to tune them both to the same channel. Once they were listening to the same channel I could send messages between the blocks and the controller without problem.

Controller Code

default
{
     state_entry()
     {
          //listen to this specific channel
          llListen(1361, "",NULL_KEY, "");
          llListen(1360, "",NULL_KEY, "");
          llSetText("Play.", , 1);
     }

     touch_start(integer total_number)
     {
          llSay(0, "Playing!");
          llSay(1360, "Hi there!");
     }

     //listen for something to happen
     listen(integer channel, string name, key id, string message)
     {
          if(message = "3 White")
          {
               llSay(0,"Three piece white lego pressed!");
          }
     }
}

Block Code

default
{
     state_entry()
     {
          //make it so they can walk through this
          llSetStatus( STATUS_PHANTOM, TRUE);
          //listen to this specific channel
          llListen(1361, "",NULL_KEY, "");
          llListen(1360, "",NULL_KEY, "");
          //you can say something like this
          llSay(1361,"Pressed");
     }
     
     //listen for something to happen
     listen(integer channel, string name, key id, string message)
     {
          if(channel == 1360)
          {
               llSay(0,"Hahahaha! That tickles!!");
          }
     }

     //or whisper something like this and still
     //send a message to the controller
     llWhisper(1361, "3 White");

     }
}

You may also like...

5 Responses

  1. Billy says:

    Hey Greta, I’ve got some good news…I think I solved our chat interference problem! Though my idea for turning all llSay’s into llOwnerSay’s would’ve worked, it would’ve made it so we were the only ones who could use our visualizations (i.e. Dr. Polack/others couldn’t try/test it out).

    Instead, what I’ve figured we can do is have the all the objects that use chat to instead instant message the person who touched the object. This solves both our problems! The text is no longer in 0 (the main chat channel), and the blocks respond to whoever touched them! There’s a tiny bit of delay, but that’s only noticeable if you’re trying to click the same block in rapid succession (so it’s not a problem for what we need.

    Before I post the code, I’ll also explain what’s around it. While playing around with my bars today, I realized something pretty important: though objects can be phantom/invisible, they’ll still respond like normal if you click them! Thus, I figured that if you make it so they only speak when phantom, it solves that problem (I’m pretty sure this is useful to you, because I’m assuming that if you click an object, it’ll identify itself by name for the user if they forget what it is, etc.)

    Here’s the code (and a pretty general script too!). If you have any questions about it, feel free to ask. Enjoy 🙂

    touch_start(integer total_number)
    {

    if ( !(llGetStatus(STATUS_PHANTOM)) ){
    llInstantMessage(llDetectedKey(0), llGetObjectName());
    }
    }

    Your thoughts?

  2. Jade says:

    Hey Billy,

    That sounds great! Thanks 😀
    This way we’re both happy in the long run.

  3. harshwardhan says:

    please explain me how communication between real world objects and virtual world objects takes place?

    i just want to know how the request gets served ……
    if possible plz reply me …….

  4. Jade says:

    In secondLife communication is done through channels. Basically it broadcasts a signal to all of the objects within a certain distance. You have to set the objects (not sure what you mean with virtual and real) to listen to certain channels. Once an object listens to that channel it can respond to any message that another object sends out on that channel. I hope this helps.

  5. Great! You have opened my doors to enter lsl world..
    This was the hardest question for me.. how things get communicated? thanks again.. great article

Leave a Reply