Jump to content

Hud object messaging Attached (worn)object


Xxaxx Constantine
 Share

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

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

Recommended Posts

Hello,

I'm looking for the most efficient way for a hud menu to message a script contained in an object that being worn by the Avatar.

At first I was hopeful that since the hud object is attached to the AV and the worn object is attached to the AV that somehow I could use a linked message system. That has failed so far.

Is llRegionSay the proper (i.e. most efficent, least laggy) way to go?

Or, is there another way to get these two objects on the same AV to receive message from each other?

Thanks

 

Link to comment
Share on other sites

You talking about efficency, that not an issue, regionSay just broacast a message region wise a llSay  is i think 20 meters llWisper is i think 10

Just have the channel a negative number ie -2000, but for the life of me i can not remeber if a HUD can talk to another Attachment.

 

Link to comment
Share on other sites

HUDs can easily talk to attachments.  It's done all the time.  I have a lovely pair of shoes that came with a color changer script that is driven by a rather elaborate HUD, for example.  It lets me change the color on different parts of the shoe, do a perfect match to my skin color, and choose among a half dozen options for texture.  (And delete the script fom my shoes when it's done.  :) ).

As Erik says, you communicate with llRegionSayTo(llGetOwner(),-12345,"My message goes here");  A message sent to an avatar on a non-zero channel is automatically heard by all scripts in all attachments on the av.

EDIT:  Corrected error

  • Like 1
Link to comment
Share on other sites

NP.  It's a cool function.  It's been getting very heavy use since LL added it about a year and a half ago.  It saves a LOT of trouble not only in situations like this but in plenty of cases where you want to be able to communicate with many people or objects without having to create a separate channel for each one.  You just use one channel but llRegionSayTo the various objects on that channel by addressing them by UUID.

Link to comment
Share on other sites

Which comm function to choose is rightly identified here based on the clean functionality of llRegionSayTo(), so I can't add much to that, but I noticed some discussion of efficiency, and it reminded me of something I was told long ago: range filtering is not free.  That is, it costs the sim some amount of time to llWhisper() compared to llRegionSay() because it has to screen potential recipients by distance. It also may have to check neighboring sims, where llRegionSay() is strictly local to the sim.

I never followed up on that, sort of assuming that it was too far behind the scenes to be directly measured in script times, but I was on an empty sim coincidentally playing around with script times in another thread, and gave it a try:

 

 

default{    state_entry()    {        integer manyReps = 256*256;        integer chan = -1000000000 - (integer)llFrand(1000000000.0);        key owner = llGetOwner();        integer rep = manyReps;        llResetTime();        do            llRegionSay(chan, "foo");        while (--rep);        llOwnerSay("llRegionSay: "+(string)llGetTime());        rep = manyReps;        llResetTime();        do            llWhisper(chan, "foo");        while (--rep);        llOwnerSay("llWhisper: "+(string)llGetTime());        rep = manyReps;        llResetTime();        do            llRegionSayTo(owner, chan, "foo");        while (--rep);        llOwnerSay("llRegionSayTo: "+(string)llGetTime());    }}

 

 

 

llRegionSay: 56.566510
llWhisper: 84.297300
llRegionSayTo: 95.547790

I'm a bit surprised by the cost of the llRegionSayTo(). It suggests to me that it first selects listeners by the "To" UUID before selecting by channel... which, come to think of it, makes sense for busy channels, and that's when it would matter.

Link to comment
Share on other sites

Our region is not super busy, and it is not totally quite.

Running the tester I get about the same results.

llRegionSay: 57.099980
llWhisper: 88.222660
llRegionSayTo: 96.620320


I was thinking about this.

The relative difference between llWhisper and llRegionSay makes llRegionSay look great whenever one is using a channel for communication. Obviously llWhisper makes sense when speaking on public channel to nearby AVs.

So in my mind, the use of llWhisper is off the table.

When choosing between llRegionSay and llRegionSayTo, I guess it would depend on whether or not the channel was unique.

Seems that if the channel was unique and only one script was "listening" in. Then llRegionSay might be the way to go.

But, if I had 100 grape plants and one basket listening to the same channel. If a grape plant script wanted to send a message to the basket script llRegionSayTo might be best. That way I don't have 99 fellow grape plants being activated as a result of the message.

Of course there is (at least) one other consideration... script self-documentation. If one uses llRegionSayTo in a script it is clear to any reader (even yourself after brain freeze) that the message is intended for a single target script.

 

 

Link to comment
Share on other sites


Xxaxx Constantine wrote:

[ ...]

So in my mind, the use of llWhisper is off the table.
[ ...]


Actually, llWhisper is a perfectly good solution in this case, since you only have one object listening and it's always going to be very nearby. llRegionSayTo becomes more useful, as you said, when there is more than one object potentially receiving messages on the same channel.  That might be the case if you had attachments on both legs and both arms and you wanted them to all respond to the same HUD, but not at once.  Personally, I'm less concerned about the slight differences in efficiency among these options than I am about using a function that's most appropriate to the job.

 

Link to comment
Share on other sites

@All

Programming (eg; LSL scripting) is always a tradeoff between development time, execution speed, memory usage and maintainability, amongst other considerations.  The first rule always has to be 'get something working' before attempting to optimise it for any particular feature.  Personally, I aim for maintainability first and only care about the rest if/when they are a sugnificant issue (where 'significant' is subject to whim, provided functionality is correct).

Link to comment
Share on other sites

I agree that getting  a script to work first then tighten it over time, I try to avoid loops if i can. Over complicated scripts are hard to work with later some examples i have used turned out 6 months later when learnt more were so complicated for what it was doing. I not a programmer but i can see LSL is a bit crude, but thats what we got so functions in an appropriate place is all i can do.

Link to comment
Share on other sites

  • 5 months later...

Hello all - Hope someone can help me with this?
I am trying to get a HUD menu to work, It needs to send a command to an attached sword to draw or sheath itself. I have been attempting to assemble something from the example scripts I have found, but with no success,
I am using the LLRegionSay message, as that was recommended, and feel like I'm simply missing something very basic.
Any advice is very appreciated!


Here is the script I am using on the HUD button:
--------------------------------

integer gListener; default{    touch_start(integer total_number)    {        llListenRemove(gListener);        key user = llDetectedKey(0);        gListener = llListen(-33, "", user, "");        llDialog(user, "\nPlease select your action", ["draw", "sheath" ] , -33);        llSetTimerEvent(10.0);    }    listen(integer chan, string name, key id, string msg)    {               if (msg == "draw")        llRegionSayTo(llGetOwner(),-999,"draw");        llSetTimerEvent(0.1);         else if (msg == "sheath")        {        llRegionSayTo(llGetOwner(),-999,"sheath");        llSetTimerEvent(0.1);        }           }    timer()    {        llListenRemove(gListener);                llSetTimerEvent(0.0);    }}


---------------------------

And this is the one that goes in the sword scabbard:

list links = [ 1,2,3];integer AOchannel = -999;integer i;float   sheathdelay = 1.0;float   drawdelay = 0.4;unHide() {    for (i = 0; i < llGetListLength(links); i++) {        llSetLinkAlpha(llList2Integer(links, i), 1.0, ALL_SIDES);    }}default {    attach(key avatar) {        if (avatar != NULL_KEY) {            llListen(AOchannel, "", llGetOwner(), "");            unHide();        }    }    listen(integer channel, string name, key id, string message) {        if (channel == AOchannel && id == llGetOwner()) {            if (message == "draw") {                llSleep(drawdelay);                for (i = 0; i < llGetListLength(links); i++) {                    llSetLinkAlpha(llList2Integer(links, i), 0.0, ALL_SIDES);                 }            }            if (message == "sheath") {                 llSleep(sheathdelay);                unHide();            }        }    }}

 Much thanks!!

Link to comment
Share on other sites

You're better off creating a new thread for this, but I think I found the issue:

Avatars can't respond on a negative channel, your llDialog channel should use a positive channel (above 0).

I do have some additional notes, also:-

1. You're calling llListen inside of attach() without checking for existance, this will cause a Too Many Listens script-error eventually.

2. Anyone can draw or sheath this sword, as you're using llDetectedKey(0) - make sure it's limited to llGetOwner() if you don't want others hiding your sword mid-battle.

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3915 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...