Jump to content

setting up if statement when llCastRay result is empty


Xander Lopez
 Share

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

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

Recommended Posts

I am trying to set up if statement when llCastRay returns nothing. But it is not working as I expected.  I think llCastRay is still returning some results when it didn't find any hit.

I have the following llCastRay:

list myValue = llCastRay(start,end, [RC_REJECT_TYPES, RC_REJECT_LAND | RC_REJECT_PHYSICAL | RC_REJECT_NONPHYSICAL, RC_MAX_HITS,1]);

 

Let's say that I want to see if the result of llCastRay that didn't hit anything. I was expecting that the list myValue would return nothing in this case. 

But noticed myValue was returning 0 instead. And the length of myValue was returning 1.

 

Would the following 'if statement' be correct to see if llCastRay hit anything?

if(llGetListLength(myValue) == 1)
            {
                llOwnerSay("No hit found!");

            }
            else
            {
                llOwnerSay( "Yes! You hit " + (string)(llList2Key(myValue,0)) );

             }

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

As per the specification on the wiki page for llCastRay:

Quote

Returns a list of strided values with an additional integer status_code on the end.

and

Quote

status_code is a number tacked onto the end of the strided list to give you extra information about the ray cast. If the cast succeeded, it will be >=0 and will indicate the number of hits. If the ray cast failed (which should only happen right now if the simulator performance is running low), you'll get a negative status code.

So the list returned from a call to llCastRay will never be empty - at minimum it will always contain a status_code integer at the end. Since the status code will always be the last entry in the list, you can use -1 as an index into that list element and check its value. And since it's always going to be an integer, you can use llList2Integer to see if it's 0 (no hits) greater than 0 (hits) or less than 0 (error).

if (llList2Integer(myValue, -1) == 0)   //status_code is 0, so the ray didn't hit anything

 

  • Like 3
Link to comment
Share on other sites

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