Jump to content

Texture changer script with llListen function change all furniture! Help!


Galatheus
 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

Well, I have a furniture with an option to change the texture. The script uses a listen function as it has a remote script and a receive script. The problem is when I rez multiple copies of the same furniture, and I try to change the texture of one of them it changes all the copies as well because they all have the same channel in the script. I only want the object i touched to change and not all of them.

Receive script looks like this:

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

    listen( integer channel, string name, key id, string message )
    {
        if (llGetOwnerKey(id) != llGetOwner())
        {
            return;
        }     
       
           
        if (message == "tex1")
        {        
           
         llSetTexture("UUID",1);
        }
        if (message == "tex1")
        {
             
         llSetTexture("UUID",2);
        }
         if (message == "tex1")
        {
             
         llSetTexture("UUID",3);
         
        } if (message == "tex1")
        {
             
         llSetTexture("UUID",4);
         
        } if (message == "tex2")
        {
             
         llSetTexture("UUID",1);
         
         } if (message == "tex2")
        {
             
         llSetTexture("UUID",2);
        }
        if (message == "tex2")
        {
             
         llSetTexture("UUID",3);
        }
        if (message == "tex2")
        {
             
         llSetTexture("UUID",4);
        }
    }
}

Button script looks like this

integer menu_handler;
integer menu_channel;
integer channel_control = 123;
menu(key user,string title,list buttons)
{
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(5.0);
}

default
{
    state_entry()
    { llSetTouchText("Remote!");
    }
    touch_start(integer t)
    { 
        menu(llDetectedKey(0),"Choose your label",["Brown","White"]);
    }
    timer()
    {
        llSetTimerEvent(0.0);
        llListenRemove(menu_handler);
    }
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel)
        {
            if(message == "Brown")
            {
               
         llWhisper(channel_control,"tex1");
            } 
            if(message == "White")
            {
               
         llWhisper(channel_control,"tex2");
            }
             
        
// llSleep(0.50);
 
// llSetColor(<1,1,1>, ALL_SIDES);
        } 
    }
}

 

Link to comment
Share on other sites

So, instead of using channel 123 in each piece of furniture, change the channel.  Or -- a better option really -- combine the two scripts into one, so that you don't need  the channel_control variable at all. After all, why would you want a remote control texture changer if you could just click on the furniture itself?

Link to comment
Share on other sites

Fixed your first script for you so it's easier to read. Of course, you do know that this one is not going to work unless a texture called UUID exists in the inventory of the root of the item that this script is in. 

 

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

    listen( integer channel, string name, key id, string message )
    {
        if (llGetOwnerKey(id) != llGetOwner()) return;
      
        if (message == "tex1")
        {  
         llSetTexture("UUID",1);             
         llSetTexture("UUID",2);
         llSetTexture("UUID",3);
         llSetTexture("UUID",4);
         
        } else if (message == "tex2")
        {    
         llSetTexture("UUID",1);
         llSetTexture("UUID",2);
         llSetTexture("UUID",3);
         llSetTexture("UUID",4);
        }
    }
}

Note that this can be done more elegant and with less code, but I only made it easier to read.
I also cleaned up the second one a bit...

integer menu_handler;
integer menu_channel;
integer channel_control = 123;
menu(key user,string title,list buttons)
{
    menu_channel = (integer)(llFrand(99999.0) * -1);
    menu_handler = llListen(menu_channel,"","","");
    llDialog(user,title,buttons,menu_channel);
    llSetTimerEvent(5.0);
}

default
{
    state_entry()
    { 
        llSetTouchText("Remote!");
    }
    touch_start(integer t)
    { 
        menu(llDetectedKey(0),"Choose your label",["Brown","White"]);
    }
  
    timer()
    {
        llSetTimerEvent(0.0);
        llListenRemove(menu_handler);
    }
  
    listen(integer channel,string name,key id,string message)
    {
        if (channel == menu_channel)
        {
            if(message == "Brown")
            {  
         		llWhisper(channel_control,"tex1");
            } 
            if(message == "White")
            {
         		llWhisper(channel_control,"tex2");
            }
        } 
    }
}

With that out of the way, on to your question:
 

1 hour ago, Galatheus said:

I only want the object i touched to change and not all of them.

The solution is ridiculously simple. Just change the state_entry() event to a touch_start() event in your listener script and add a listen timeout just like in the button script.
Why will this work? Because each copy of your furniture has opened a listen by default so all of them will respond if hey recieve a message on channel 123, even when an avatar were to say something on channel 123, this is generally a bad idea and you have already ran into one of the reasons why that is a bad idea and Ijust highlighted one other.

So start a listen on touch and only keep it active for like 15 seconds, then reset the timer to 15 each time a choice is received in case you want to change your mind, otherwise your listener will stop listening while you are till trying to make up your mind if you want a white or a brown couch and that gets annoying really fast.

There are better solutions, but only if you want to start over from scratch...

Link to comment
Share on other sites

  • 2 months later...
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...