Jump to content

How would a script hear multiple things at once? (Or a separate way to do it).


Strider Kling
 Share

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

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

Recommended Posts

Hi, I wasn't sure if this was already posted, but I figured it would be good for a lot of people, not just me. I have a project I'm working on kind of like a scavenger hunt. When you have all 7 objects, they show on your hud. Then you can press a button to rez your prize. I was going to make it so it says something, and makes sure to hear it form all objects before rezzing the prize, but the only way I know how is to make a very laggy, extremely long messaging script. Is there a way to do this in a siimpler, less laggy way?

Link to comment
Share on other sites

Each object can have its own channel number and you can "Listen" to as many channels as you like.

HOWEVER,

Sending out queries to check status on objects already in your HUD seems to be the wrong way to do it.  As each item comes in you can check it off on an array to keep a local record of what has come in.

Link to comment
Share on other sites

yes.... round robin style is one way

each piece has a single listen, and a single message that it sends when it gets the exact message it is listening for from an object owned by the same person, on a specific channel. the hud can be touched to say the first message, which the first item listens for, and if it receives it sends the message the second is looking for, until the last one which sends a message the hud is listening for to trigger the prize

another alternative, was used by excite as part of one of their hunts, each item sends a message when it is touched, and the hud or listening item can either remove that item from the list it's listening for (until it reaches no items, and triggers) or do them in sequence, listening for the first item, then when heard, listen for the second item (if an out of order item comes in, then reset to listening for the first)

 

Link to comment
Share on other sites

Thank you, the second way was a much easier way. For future people with this same problem, heres a simple script I set up (it could probably be done better, but yah...)

 

string owner;
string db1;
default
{
    state_entry()
    {
        owner = llGetOwner();
        llListen(0,"","","");
    }
    listen(integer channel,string name,key id,string message)
 {
     if(message == owner + " db1 in")
     {
         db1 = "on";
        }
        if(message == owner + " db1 off")
        {
            db1 = "off";
        }
    }
    touch_start(integer total_number)
    {
        if(db1 == "on")
        {
            llSay(0,"on");
        }
        if(db1 == "off")
        {
            llSay(0,"off");
        }
    }
}
Link to comment
Share on other sites

I created a HUD a while back for one of my University clients. As the wearer of the HUD walked through an SL orientation course, at the completion of each lesson station, the HUD recorded their progress. If they completed all the stations, they could collect a prize from a station at the end. And they didn't have to complete them in any specific order, though the trail walk presented them in what I hoped was a logical progression for the material.

The same method could be used for your hunt. When the wearer attaches the HUD for the first time, it learns their name and UUID key, and sets a communication channel for the lesson stations. The HUD sets a channel unique for each wearer, so the huds don't cross-talk with each other. When the wearer touches a prim for the "item giver" his HUD tells the giver prim the channel to reply on for that specific user's UUID, and touching any station (or walking through a volume detect prim, or whatever method that station uses to determine success) also detects the UUID of the avatar, so the station knows who to reply to. They get given a notecard (or a prize), and the giver prim says a code word on that wearer's channel, so his HUD can record the success for that station.

The status was recorded in a 12-character text string, kept in the description field of a non-root prim in the HUD. Each character represented one station. A  1 indicated task completed, 0 for task yet to be done. The HUD displayed numbers for each station, with a star overlaid on the completed tasks. 

At the final station, the station queries the hud for that status code variable, and if it matches what it should be, they get a prize for completing all the stations. If not, it tells them they have more stations to complete.

Kind of complex to set up, but you can have a sim full of people all using their HUDS at once, and each avatar only needs to communicate with one station at a time.

Go to the "Rutgers University" sim and try the orientation course, to see the concept in use. Station one gives you a brand-new, un-personalized HUD. After you wear it the first time, The HUD remembers who you are and what channel you use, even if you detach it and put it on again later.

Link to comment
Share on other sites

 


Strider Kling wrote:

Thank you, the second way was a much easier way. For future people with this same problem, heres a simple script I set up (it could probably be done better, but yah...)

 
string owner;
string db1;
default
{
    state_entry()
    {
        owner = llGetOwner();
        llListen(0,"","","");
    }
    listen(integer channel,string name,key id,string message)
 {
     if(message == owner + " db1 in")
     {
         db1 = "on";
        }
        if(message == owner + " db1 off")
        {
            db1 = "off";
        }
    }
    touch_start(integer total_number)
    {
        if(db1 == "on")
        {
            llSay(0,"on");
        }
        if(db1 == "off")
        {
            llSay(0,"off");
        }
    }
}

 

@Strider : I tried to give you "Kudos" for your post.  Anyone that posts code deserves Kudos in my book.

Alas, I lack the Kudo priviledge.  So I write this swell reply to you instead!!

Cheers!

Link to comment
Share on other sites

Surely Kudos should only be given for GOOD code!

First - let's not have an open listen on the public chat channel (llListen(0,"","","");) EVER.

Second - what's if(message == owner + " db1 in") meant to be doing?  It won't be listening to its owner, that's for sure - except that that open listener will hear everyone.  I assume it's all about checking if something else is talking to the owner, but is that really something you want in public chat?

Third - if you're going to store the owner you almost certainly need to change it on CHANGED_OWNER

Fourth - since db1 is 'on' or 'off' why not just say so in the touch event?  While we're at it, don't say that in open chat either!

How about:

 

string Thing;default{   state_entry(){      llListen(-2000, "", "", "");   }   listen(integer In, string From, key ID, string Msg){      list Words = llParseString2List(Msg, [" "], []);      if(llGetOwner() == (key) llList2String(Words, 0)){         if("Thing" == llList2String(Words, 1)){            Thing = llList2String(Words, 2);         }      }   }   touch_end(integer Counter){      llInstantMessage(llDetectedKey(0), Thing);   }}

 

 

Link to comment
Share on other sites

If you have 7 listens running, you are adding a good bit of load to the sim.  Better is to create a datagram structure that all your items follow and has all the data within it.   And all your items talk on a single comm channel as much as possible. 

For example, suppose I have 12 welcome mats with Volume detect on them and I want to signal the hud to switch to a different mode when you walk into a certain place.  I would then have all the welcome mats talk on the same channel and preface the user's UUID as the first part of the string that's broadcast.  Then I send the objects name and what has happened with that object.

 

"XXX-XXX-XXX;MAT1;TRIGGER"

 

When the HUD sees a message, it checks that the UUID is for its owner.  If so, it looks at the next string in the delimited set and acts appropriately.  And the next bit of string, and so on and on.  You get the UUID of the avatar when the collision start or touch events occur, so this is simple to implement.  And since every welcome mat and hud is the same with the exception of its name, building elaborate and massive builds is also simple to implement.  Doing this means your item only has to listen to a single channel, a considerable saving for the sim. 

Link to comment
Share on other sites

  • Lindens

As long as the 7 channels are not very active, having the 7 listens isn't going to be a very big deal. In general the overall message rate on the observed channels is a bigger factor than the number of listens, that and how much work is done on each received message. It is possible that the number of listens would have a noticable impact in some more excessive case. At this scale the best thing you can probably do is to make the code as simple and clear as possible for you (the developer). Simple and clear code will be easier to follow, improve and debug and thus lead to better sim performance overall.

Shockwave's suggestion is still a good one - and in many cases maybe easier to follow than lots of listens.

 

Link to comment
Share on other sites

  • 6 months later...
You are about to reply to a thread that has been inactive for 4611 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...