Jump to content

how do I make an object listen to a hud?


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

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

Recommended Posts

ok, heres what I mean... I have 5 objects that need to listen to one hud. the listen objects 0-4 each work when it is typed in the chat box. IE: "/86 0" will turn all objects into, "off" position. but I want a hud to control these instead of typing,, for convinience, effect, and quality.

how do I make the objects in question respond to a hud button?

here is an example of the script Im using in one of the objects (colored for your convienience ^_^ )

default

 {     state_entry()     {         llListen(86,"",llGetOwner(),"");

     }     on_rez(integer message) {      llResetScript();

       }     listen(integer channel, string name, key id, string message) {      

if(llToLower(message) == "1")

            llSetAlpha(1.0,ALL_SIDES);

   

      if(llToLower(message) == "0")

             llSetAlpha(0.0,ALL_SIDES);

 

                   if(llToLower(message) == "2")

             llSetAlpha(0.0,ALL_SIDES);

 

                   if(llToLower(message) == "3")

             llSetAlpha(0.0,ALL_SIDES);

 

                  if(llToLower(message) == "4")

             llSetAlpha(0.0,ALL_SIDES);         }    

    }

 it'd be really great if I could get a reply on this, Im kinda noobish to scripting lol...

 thanks in advance,

-Harru

Link to post
Share on other sites

You basically have everything you need. Just make the HUD use a different channel for each object - and I would rather use low negative numbers for the chat then numbers like 86 - use e.g. -56433456

In the HUD, use e.g. 

llRegionSay(-56433456, "0");

 If the object are closer by, you can use llWhisper or llSay. If the objects are attachments, you can use llRegionSayTo as well. 

Link to post
Share on other sites

Ok first thing I did was clean up some things in your sample script.  First, since all your values are numbers no reason to call tolower, it just adds extra cycles.  Second, the way your script is written now every if statement is checked even though the value can only be one of them.  Therefore, it is more effecient to use else if, then the script only checks until it gets to the correct value.  Final change, since the value is going to come from a hud and not typed chat text I changed the listen channel to a large negative number.

 

default{	state_entry()	{		llListen(-864563,"",llGetOwner(),"");	}	on_rez(integer message) {      		llResetScript();	}	listen(integer channel, string name, key id, string message) {      		if(message == "1")            		llSetAlpha(1.0,ALL_SIDES);		else if(message == "0")        		llSetAlpha(0.0,ALL_SIDES);		else if(message == "2")			llSetAlpha(0.0,ALL_SIDES);        	else if(message == "3")            		llSetAlpha(0.0,ALL_SIDES);        	else if(message == "4")			llSetAlpha(0.0,ALL_SIDES);	}    }

 Actually, since your actions for values 2, 3, 4 are all the same action I would have written it a bit differently doing it myself.  I am going to assume there will be a slightly different action for each of these values and leave them broke out like you have it.

As for the button script, a simple say on the negative channel will work.  This has a range of 20m, whisper would give a range of 10m. Here is the script for inside the button

default{	touch_start(integer total_number)	{		llSay(-864563, "0");	}}

 

 

Link to post
Share on other sites

actually... now that I tried it. none of those worked. I set the channel to -54200.

I did the region say I did the say, I did the whisper. I even typed "/-54200 1" into the chat box and it did nothing.

negative numbers dont seem to work at all, when I typed them, it just displayed "/-54200 1" in the chat window.

anybody have any other suggestions??

Link to post
Share on other sites

 this would be the sending code... the one in the hud button.

default{    touch_start(integer total_number)    {        llSay(-54200, "shikai");    }}

and this is the listening script. the one in the object.

default{    state_entry()    {        llListen(-54200,"",llGetOwner(),"");    }    on_rez(integer message) {     llResetScript();       }    listen(integer channel, string name, key id, string message) {      if(llToLower(message) == "shikai")           llSetAlpha(1.0,ALL_SIDES);        else if(llToLower(message) == "off")            llSetAlpha(0.0,ALL_SIDES);                 else if(llToLower(message) == "bankai")            llSetAlpha(0.0,ALL_SIDES);                else if(llToLower(message) == "hiddenbankai")            llSetAlpha(0.0,ALL_SIDES);                 else if(llToLower(message) == "sealed")            llSetAlpha(0.0,ALL_SIDES);        }        }

 these are the exact scripts Im using.

even disclosing the names of the keywords.

Link to post
Share on other sites

You use negative channel if you have objects speaking to other objects.  That's exactly what you want to do in this case.  Your HUD (object A) is speaking to your distant objects (B,C,D,E ...).  So all you need is a HUD script.  You could do it by building a multiprim HUD and putting a separate script in each button, as someone else suggested above, but that's kind of a wasteful use of resources.  A nicer solution is to use a single prim and just make different portions of it sensitive to touch -- like mapping URLs on an image on a web site.  Suppose you want to speak to four objects, for example.  Divide your HUD prim into four quadrants and write something like....

 

default{    touch_start(integer num)    {        integer MSG;        vector Button = llDetectedTouchST(0);        if (Button.x < 0.5)        {            if (Button.y < 0.5)    // SW quadrant            {                MSG = 3;            }            else            {                MSG = 1;    / NW quadrant            }        }        else        {            if (Button.y < 0.5)    // SE quadrant            {                 MSG = 4;            }            else    // NE quadrant            {                MSG = 2;            }        }        llRegionSay(-289467, (string)MSG);   //Send the message    }}

 Just remember that your receiving scripts will hear the MSG as a string.

 ETA:  Your posted your response while I was typing mine.  :smileytongue:  So, since you have five possible responses instead of four, divide your HUD prim into five parts (Button.x < 0.2, (Button.x >=0.2) && (Button.x < 0.4), and so forth) and make your MSG a string instead of an integer as I suggested.  

 

Link to post
Share on other sites

@rolig

I agree its more effecient the way you suggest.   I was just trying to start simple :smileyhappy: 

 

@harrutriegenn

I still think the tolower calls are not needed even though you are passing more than just numbers now.  You control both the sending source, the hud, and the receiving items your listening objects.  Therefore you won't ever have a case miss-match.  Just my two cents.

Link to post
Share on other sites

nah, it doesnt even let me push the button when i add that...

-edit:

someone said I should get rid of the llGetOwner. and that should take care of it, but my biggest concern with that, is, what if I plan on selling this in the sl market and 2 people have the same item, the llGetOwner makes sure its the owner telling it what to do, but if I take that out, some one elses hud will mess with your item... or anyone who knows the key words can mess it up...

Link to post
Share on other sites


harrutriegenn wrote:

nah, it doesnt even let me push the button when i add that...

-edit:

someone said I should get rid of the llGetOwner. and that should take care of it, but my biggest concern with that, is, what if I plan on selling this in the sl market and 2 people have the same item, the llGetOwner makes sure its the owner telling it what to do, but if I take that out, some one elses hud will mess with your item... or anyone who knows the key words can mess it up...

Oh, that part's easy.  Just create a negative channel out of the owner's UUID.  Use the same formula in each of your scripts  so that they all have the same unique channel.

integer gChan = (integer) ( "0xF" + llGetSubString( llGetOwner(),0,6 ) );

 

Link to post
Share on other sites


Talia Davidov wrote:

@rolig

I agree its more effecient the way you suggest.   I was just trying to start simple :smileyhappy: 


I love simple. I wasn't tossing a rock at you, Talia.  Just trying to save the OP from designing a HUD with five times the prims and scripts that he needs for a really easy job.  :smileywink:

Link to post
Share on other sites
  • 2 years later...

Hello harrutriegenn,

The script from Talia Davidov will not work but here is one that does and I'll tell you why....
The listener needs to know the owner key of who is saying what you get this by using the general tab in edit mode and clicking copy keys. You will want to copy the keys from the HUD button or whatever is running the touch/sender script. Put the Sender script in the HUD button and the Listener Script in the listening object. I'm assuming you know how to attach a hud to your screen and will leave you with the keep it simple stupid code that took me awhile to figure this out too. Bringing something down to it's purest form is sometimes what makes things easy then I just keep them as templates for future use. Just a piece of advice ;)

Sender Script:
default
{
    //When someone starts touching the prim
    touch_start(integer num_detected)
    {
        llSay(-99, "Button 1");
    }
}

Listener Script:
default
{
//  when the script has been saved (only in default) or when re-entering this state
    state_entry()
    {
        key owner = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; //Where the x's are put the key we talked about
 
        llListen(-99, "", owner, "");
    }
 
//  when something has been heared
    listen(integer channel, string name, key id, string message)
    {
        if(message == "Button 1"){
            llSay(0, "works"); //Execute your commands here
        }
        llSay(0, "Received: '" + message + "'.");
    }
}

Now since we deduced that the listener scrpt needs a UUID then lets listen to all then filter it to owner only

Listener Script Revised: (Use this one)

default
{
    state_entry()
    {
        llListen(-99,"","",""); //listen to messages from anyone and anything on chan 99
    }
    listen(integer channel, string name, key id, string message)
    {
        if(llGetOwnerKey(id)==llGetOwner()){//if the object sending the message belongs to my owner (or is my owner)
            //then its for me
            llSay(0, "Button 1 Clicked!");
        }
    }

}

Link to post
Share on other sites

Talia's script in this two and a half-year old thread ought to work just fine.  Her listen is opened with

llListen (-99,"",llGetOwner(),"");

which will pick up the owner's UUID directly.  There's no need to grab it manually and drop it in.  I suspect that the OP has figured it out by now anyway.  :smileywink:

Link to post
Share on other sites

Sorry to disagree, Rolig, but I think something's gone wrong withl lilypadgurl's  code.

llListen(-99, "",llGetOwner*,());

is never going to hear anything under normal circumstances, since the only time an avatar can speak on a negative channel is when it makes a choice using llDialog, which doesn't seem to be happening here.

I think the way to do it is  to put this in the start of both scripts, to make sure they're both communicating on very negative channel based on their owner.

integer MyChannel;key MyOwner;default{	state_entry()	{		MyOwner = llGetOwner();//store the owner's uuid as a constant, because you often need to check it several times, and it's pointless to keep on looking it up		MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);//perform some bitwise magic that makes Innula's head ache, and you end up with long, unique, negative number based on the owner's uuid	}	changed(integer change)	{		if (change & CHANGED_OWNER){ //something's changed!  Was it my owner?  Yes, it was. 			llResetScript();//reset the script when my owner changes, to you recalculate the value of MyChannel		}	}}

 

then, in the listener script, say in the listen event, 

 

integer MyChannel;key MyOwner;default{	state_entry()	{		MyOwner = llGetOwner();//store the owner's uuid as a constant, because you often need to check it several times, and it's pointless to keep on looking it up		MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);//perform some bitwise magic that makes Innula's head ache, and you end up with a long, unique, negative number based on the owner's uuid	}	changed(integer change)	{		if (change & CHANGED_OWNER){ //something's changed!  Was it my owner?  Yes, it was. 			llResetScript();//reset the script when my owner changes, to you recalculate the value of MyChannel		}	}	listen(integer channel, string name, key id, string message)	{		if (llGetOwnerKey(id)== MyOwner){//if the object that's talking to me belongs to my owner, then...			//go ahead and do stuff.   Anything you want to happen, make it happen inside these brackets		} //this closing bracket goes right at the end of the event, just before the listen event itself finishes	} //end of listen event}

 

Link to post
Share on other sites
  • 3 years later...

Well since this is very close to what I am trying to do, I am going to post here my problem instead of a new topic.

I am building a HUD with multiple prim buttons for one of my products. The HUD should send to a mesh object (with multiple faces) just the HUD button name that was touched, and the listener should take care of the rest with consequent if and else ifs. Before I even get to the point to set the code for each button touch, I try a simple llSay for both HUD and Listener object to see if they communicate, and while the HUD seem to send the right information, the Listener script doesn't seem to listen anything.
Here is the source code for HUD:
 

integer MyChannel;
key MyOwner;

default
{    
    state_entry()    
    {    
        llPassTouches(TRUE);    
        MyOwner = llGetOwner();//store the owner's uuid as a constant, because you often need to check it several times, and it's pointless to keep on looking it up       
        MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);//perform some bitwise magic that makes Innula's head ache, and you end up with long, unique, negative number based on the owner's uuid    
    }    
    changed(integer change)    
    {        
        if (change & CHANGED_OWNER)
        { //something's changed!  Was it my owner?  Yes, it was.             
            llResetScript();//reset the script when my owner changes, to you recalculate the value of MyChannel        
        }    
    }
     touch_start(integer total_number)
    {
        if(llDetectedKey(0) == llGetOwner())
        {
         //Detect which button was touched
        integer button_link = llDetectedLinkNumber(0);
        string button_name = llGetLinkName(button_link);
         //Announce the button name
        llOwnerSay("Touched "+button_name);
       // llOwnerSay("Channel "+(string)MyChannel);
        llSay(MyChannel,button_name);
        }
    }
}

And this is the code for the Listener script:

integer MyChannel;
key MyOwner;
default
{    
    state_entry()    
    {        
        MyOwner = llGetOwner();
        MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);
        llListen(MyChannel,"",NULL_KEY,"");  
        llOwnerSay("Channel "+(string)MyChannel); //prints nothing on screen
    }    
    changed(integer change)    
    {        
        if (change & CHANGED_OWNER)
        { //something's changed!  Was it my owner?  Yes, it was. 
             llResetScript();
        }    
    }    
    listen(integer channel, string name, key id, string msg)    
    {       
		llOwnerSay("Channel "+(string)MyChannel); 
    	llSay(0,"Received "+msg);  //prints nothing on screen

        if (llGetOwnerKey(id)== MyOwner)
        {            
            llSay(0,"Received "+msg); //prints nothing on screen
        }  
    } 
}

Am I missing something?

Link to post
Share on other sites

As a matter of fact...NO!
Duh...

I reset the script so many times while trying to set my llSetPrimitiveParams and I must have accidentally clicked the "Running" box..
Thanks Xiija!
And since we are on the subject...the initial thought was to have my texture UUIDs on the HUD script and send them via the channel to the Listener but I was wondering if there are possible security risks or should I keep them on the Listener script?
Do I need to add any other bits of code for a more secure communication between the 2 objects to avoid UUID theft?

Link to post
Share on other sites

You could add a product channel offset  to help keep all your items

on separate channels, and add a lil more security?

        integer chan_offset = -545;  // a unique integer for each hud/product pair?
        MyOwner = llGetOwner();
        MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);  // the basic owner-key channel hash .. which anyone can  get easily?
        MyChannel += chan_offset;
        llListen(MyChannel,"",NULL_KEY,""); 

 

I can't comment on sending the UUID from a HUD to a prim...

I've been trying it in-world, but I'm having  trouble getting it to work (grrr)

***For the receiver,  i linked 2 boxes, and put this in the root , then i made 2 more boxes for the HUD and when clicking

the child on the HUD ( supposed to be the button, it's name is "2" ) it seems to send okay, but i'm not getting the texture ?

prolly something easy i am missing :P

the HUD is sending this... 2,4d304955-2b01-c6c6-f545-c1ae1e618288,0

( link number, texture uuid string, face number )

RECEIVER prim


integer chan_offset = -545;
integer MyChannel;
key MyOwner;
integer face;
key txtr;
integer linkNum;
default
{    
    state_entry()    
    {        
        MyOwner = llGetOwner();
        MyChannel = 0x80000000 | (integer)("0x"+(string)MyOwner);
        MyChannel += chan_offset;
        llListen(MyChannel,"",NULL_KEY,"");  
        llOwnerSay("Channel "+(string)MyChannel);
        llSetLinkTexture( 2, "4d304955-2b01-c6c6-f545-c1ae1e618288" , 2);
    }    
    changed(integer change)    
    {        
        if (change & CHANGED_OWNER)
        {  llResetScript();
        }    
    }    
    listen(integer channel, string name, key id, string msg)    
    {    llOwnerSay("IN \n" + msg + "\n");
    
         list my_list = llParseString2List( msg,[" "],[" "]);   
         string tmp = llDumpList2String( my_list, "\n");
         llOwnerSay("Dbug \n" + tmp + "\n");  // DISPLAYS .... 2,4d304955-2b01-c6c6-f545-c1ae1e618288,0
         
         linkNum = llList2Integer( my_list, 0);
         txtr =    llList2String(  my_list, 1); //  txtr =    llList2Key(     my_list, 1); *** TXTR NOT WORKING
         face =    llList2Integer( my_list, 2);
         
         llOwnerSay("got " +
           "\nName-linkNum: "  + (string)linkNum +
           "\nTxtr: "          + (string)txtr +
           "\nFace: "          + (string)face );
            
        llSetLinkPrimitiveParamsFast( linkNum,
         [  PRIM_TEXTURE, face,txtr, <1.0, 1.0, 0.0>, ZERO_VECTOR, 0.0] );
    } 
}

 

Edited by Xiija
Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 940 days.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...