Jump to content

Send Message back to Raycast object.


Altier Verwood
 Share

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

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

Recommended Posts

I wasn't sure how to word the question but I can explain in more detail here.

have two working objects, one is a cast ray that shoots a ray and then sends a message to the object it hits.

the second object then takes that message and does stuff with that.

 

is there a way I can make the second object, the one being hit, send a message BACK to the object that cast the ray? so it's a two way communication.

  • Like 1
Link to comment
Share on other sites

When you receive a message in a LSL script, the listen event gives you four standard pieces of information:

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

Since you always receive that id variable, you can simply reply in the listen event with

llRegionSayTo(id, channel, "Hi, there, " + name);  // or words to that effect....   :) 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you so much! this is exactly what i needed. I had no idea LSL saved the ID like that.

28 minutes ago, Rolig Loon said:

When you receive a message in a LSL script, the listen event gives you four standard pieces of information:

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

Since you always receive that id variable, you can simply reply in the listen event with

llRegionSayTo(id, channel, "Hi, there, " + name);  // or words to that effect....   :) 

 

 

Link to comment
Share on other sites

Certainly, if you know that object's UUID.  After all, with llRegionSayTo, you can send a directed message to any listening person or object.  You can capture the seat's UUID in any number of ways. Once you have it, you're all set.  Just pass that UUID to the detected object as part of the message you send after your cast ray hits it.

Edited by Rolig Loon
Link to comment
Share on other sites

Hm I will try that, I have run into a final problem that I can't seem to solve. my ray cast continues as long as the button is held down, and each time it "fires" it sends the message to the target object, that target object then sends back a message, but the problem I have run into is.
the target object will continue to receive messages, but only returns the message, once and not each time it receives the message, is there a way to fix this?

Link to comment
Share on other sites

Yeah it only seems to be working about half the time, and then the script doesn't seem to send messages at all.  OH I'm using this. if (CONTROL_ML_LBUTTON & ( held) && ammo_count > 0) the weapon works just fine, it seems to be only the return message that gets lost and only sometimes? and I can't reproduce or figure out why it does. some times the return message gets sent from the target object, and sometimes it just doesn't. 

Edited by Altier Verwood
Link to comment
Share on other sites

That's very odd.

touch_start(integer num)
{
     list results = llCastRay(llGetPos(), llGetPos() + <20.0,0.0,0.0>*llGetRot(), [RC_MAX_HITS,2, RC_REJECT_TYPES, RC_REJECT_LAND]);
     key kTarget = ll(key)llList2String(results,0);
      llRegionSayTo(kTarget, My_secret_channel,  (string)"Chair's UUID goes here");
}

Something like that will send one cast ray to look for things within 20m in front of you, and will send the detected target the UUID of your chair (assuming that you grabbed that UUID).  When your target hears the message, all it has to do is typecast it back to a key and use that key to send its own message back to your chair.

That's written really quickly, so may have a typo in it.  If I were doing it for real, I would use camera position and rotation  instead of llGetPos and llGetRot, and I would plan on using the thing in mouselook, but that's the general idea.

Edited by Rolig Loon
Additional information
Link to comment
Share on other sites

It seems super inconsistent, but it does at least seem to be, kind of working. here is a feed from it sending messages back and forth.

okay this is very strange it seems it has to do with me moving or not, if im moving towards it it's more likely to pick up the message, what the heck. 
its getting the uuid, but only sometimes?
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[16:34] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b

Edited by Altier Verwood
Link to comment
Share on other sites

here is my ray cast.
 

list results = llCastRay(start, start+<range,0.0,0.0>*llGetCameraRot(),[RC_REJECT_TYPES,RC_REJECT_LAND,RC_DETECT_PHANTOM,FALSE,RC_DATA_FLAGS,RC_GET_ROOT_KEY,RC_MAX_HITS,1]);
            llSleep(0.03);
            key target = llList2Key(results,0);
                llTriggerSound(llList2String(llListRandomize(firesound,1),0),1.0);
                llRegionSayTo(target,gTargetChan, damage_type );
                llResetOtherScript("bullet_"+(string)slave);
                llResetOtherScript("m_f");
                //llOwnerSay("Jam % "+(string)jamchance);    

Link to comment
Share on other sites

What the heck, out of 32 hits only 1 sent back the message, but then in another test I got 14 back .... what does it mean, did i find the iluminati in SL or something? 

oh i think i got it, it might be doing either OR! if it hits one meter it doesn't really the message back,
here is the target this is what it takes to send the message back
         if (m == "Assault_Rifle")
            {
            integer chance = llRound(llFrand(100));
                if(chance>=Assault_Rifle+Global)
                {
                hp -=llRound(llFrand(Assault_RifleD)+Assault_RifleMD);
           llSetText("HP:" + (string)hp + "\n" + HP + "\n " + Faction + "\n" + Ship + "\n" + Attacks , <1.000, 0.000, 0.000>,1);
           llRegionSayTo(id, -943, "Assault_Rifle");
           llOwnerSay(id);

Edited by Altier Verwood
Link to comment
Share on other sites

Well, for starters, get rid of the llSleep.  Then, try not firing the cast ray so fast.  There's a region buffer, described in http://wiki.secondlife.com/wiki/LlCastRay#RCERR_CAST_TIME_EXCEEDED , that can mess up things if you try to send cast ray pulses too fast.  I'd put a filter on the touch_start event

touch_start(integer num)
{
    if (llGetTime() - OldTime > 0.5)
    {
         // Do stuff
    }
    OldTime = llGetAndResetTime();
}

EDIT:  OldTime is a global float variable, so it gets saved between triggering events.

Edited by Rolig Loon
Link to comment
Share on other sites

Yeah, a race condition.  You're doing things fast enough that the script is interfering with itself.  Slow things down.  Try putting a damper on the system like I suggested so that you can't fire more than a couple of times a second.  See what that does.  I think you're on the right track, so just keep plugging at it.

Link to comment
Share on other sites

NVM while loop broke it. 
So I have narrowed it down kind of, putting a delay in didn't solve the problem though, I have found that it is indeed doing either or, either it receives the message or sends one back. it can't do both. 

Edited by Altier Verwood
Link to comment
Share on other sites

It's a little hard for me to make sense of your code because I really don't see what you are trying to do.  I think your best bet is to slow down and take care of one challenge at a time.  Think through the logic in small steps, and pepper your code with diagnostic statements to be sure that it's doing what you want it to.  If you try to do too many things at once, you'll fall over yourself.

Link to comment
Share on other sites

So after much testing, I can not figure this out, it seems completely random, I tried splitting it into two scripts where each listens for a different channel, it didn't work. 

         if (m == "Assault_Rifle")
            {
            
            //integer chance = llRound(llFrand(100));
                //if(chance>=Assault_Rifle+Global)
                {
           llRegionSayTo(id, -943, "Assault_Rifle");
           llOwnerSay(id);
           llOwnerSay(m);
           llSleep(.1);
                }


this is basically what happens, it will do one or the other not both.  it will either do the region say or the owner say, and if i take out the owner say, it will only some times do the region say. 


[17:31] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCSH Flood Marine NPC 2.5: Assault_Rifle
[17:31] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCSH Flood Marine NPC 2.5: Assault_Rifle
[17:31] CGCSH Flood Marine NPC 2.5: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCSH Flood Marine NPC 2.5: Assault_Rifle
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b
[17:31] CGCS Halo Ground Meter 2.7 Listen: 1c852905-b8c0-5756-aa54-c14de4802d2b

Link to comment
Share on other sites

I'm not really sure what you are showing here, and I don't know what event that code segment is in.  You have two objects sending you messages.  The one called CGCHS Flood Marine NPC always sends you a pair of messages every time it is sent a message from your gun (I assume that's your target).  It always sends a UUID and then the word "Assault Rifle", as separate llOwnerSay messages.   It's sending your rifle (which has UUID = id) a message too, but you won't hear that unless you relay it from there to you.  Or unless you sent it to yourself instead, with llRegionSayTo(llGetOwnerKey(id),-943,"Assault_Rifle");

The other object, CGCS Halo Ground Meter 2.7, only ever sends you one message, a UUID.  I assume that you didn't tell it to send a second message.  I have no idea what triggers that second object.

So, what's the problem?

Link to comment
Share on other sites

I'm sorry, let me try to explain better,
The first object is CGCHS Flood Marine NPC, we will call that one the Target.

the second object is CGCS Halo Ground Meter 2.7 we will call that one the Receiver.

how the script works is this

 

The receiver fires a ray with a message on channel -943, the Target gets that and does this hp -=llRound(llFrand(Assault_RifleD)+Assault_RifleMD);, and fires back  llRegionSayTo(llGetOwnerKey(id),-943,"Assault_Rifle");

The Receiver is listening for that return message the llregionsay. 

the problem i have run into is the Target, can not do both 

llRegionSayTo(llGetOwnerKey(id),-943,"Assault_Rifle"); AND hp -=llRound(llFrand(Assault_RifleD)+Assault_RifleMD); at the same time, it picks randomly what one to do.

Okay on further testing it was this, I put the receiver script in another object i was wearing, not the one i was wearing that cast the ray, I thought that it would get the ID of my avatar and not the object casting the ray because I was wearing the object, I was wrong. when I put the receiver script in the same prim the cast the ray, it now works, this is a step forward but not the outcome I was looking for.  I need to test more and see if I can make some adjustments. 

Edited by Altier Verwood
Link to comment
Share on other sites

Wait ....  That's not what I understood you to say all this time.  You want it to send two pieces of information in the single message?  I thought you said before that you wanted to send two messages.

OK, so send the two pieces if information like this:

hp -=llRound(llFrand(Assault_RifleD)+Assault_RifleMD;

llRegionSayTo(llGetOwnerKey(id),-943,"Assault_Rifle" +"~"+ (string) hp ); 

Then just separate the two bits of information as they are received:

list temp = llParseString2List(message,["~"],[ ]);

string partOne = llList2String(temp,0);

integer partTwo = (integer)llList2String(temp,1);

Link to comment
Share on other sites

17 hours ago, Altier Verwood said:

Okay on further testing it was this, I put the receiver script in another object i was wearing, not the one i was wearing that cast the ray, I thought that it would get the ID of my avatar and not the object casting the ray because I was wearing the object, I was wrong. when I put the receiver script in the same prim the cast the ray, it now works, this is a step forward but not the outcome I was looking for.  I need to test more and see if I can make some adjustments. 

This thread is confusing enough I dread stepping in and potentially muddying the waters further. But in view of what I bolded above, in case it's helpful:

  1.  If llRegionSayTo() is sent to an avatar, all the listen() handlers in all the objects attached to that avatar can receive that message.
  2. The target object script's listen event has the id of the attachment that reported a raycast hit, and that script can get the OBJECT_OWNER of that id* which will be the avatar wearing that attachment.

______________
* which is functionally equivalent to llGetOwnerKey(id) if there's no other reason to call llGetObjectDetails().

  • Like 2
Link to comment
Share on other sites

30 minutes ago, Qie Niangao said:

This thread is confusing enough I dread stepping in and potentially muddying the waters further.

Yeah, I've done too much guessing about what the OP is trying to do, myself.  Time to step back and let him toy with it for a while. ;)

 

  • Like 2
Link to comment
Share on other sites

@Altier Verwood I notice now that you have gone back and edited some of your early posts in this thread.  That further confuses things, so please don't do that.  In particular, I notice that you have edited https://community.secondlife.com/forums/topic/475491-send-message-back-to-raycast-object/?tab=comments#comment-2334539 by adding this important bit of information:

22 hours ago, Altier Verwood said:

OH I'm using this. if (CONTROL_ML_LBUTTON & ( held) && ammo_count > 0) the weapon works just fine, it seems to be only the return message that gets lost and only sometimes?

If you're firing your cast ray in a control event, it's no wonder that you are getting a race condition.  I gave you a link to the throttling info last night, but here's the text (almost) in full, with some emphasis added:

"Ray casts are throttled by the amount of time actually taken to perform the cast. Full regions are each allotted a 4ms pool, divided proportionally over parcels the same way prim limits are. [ .... ] Each agent is allotted 200us. All scripts in attachments and, scripts in vehicles, use the agent pool whereas all other scripts use the parcel pool. For the purpose of ray cast accounting (and script limits in general), a 'vehicle' is defined as an object which had one or more avatars seated on it when it entered the parcel. A ray cast can be performed if at least 30us of raycast time remain in the appropriate pool. If there is insufficient time remaining, RCERR_CAST_TIME_EXCEEDED is returned as the status code. The exact time used by the ray cast is measured when it is performed and that number (in microseconds) is subtracted from the pool." 

If you trigger llCastRay in a control event, it is essentially firing continuously while you have that mouse button held down. You'll burn through your allotment in no time. This like having your gun overheat and jam in RL. It will be even more of a problem if other people in the region are doing the same thing.  

  • Like 1
Link to comment
Share on other sites

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