Second Life LSL Problems: llEdgeOfWorld()

By Xah Lee. Date:

[Note: this article is incorrect, and is kept here only as a record. See bottom for detail.]

This page documents a bad design in LSL.

Another major LSL idiocy.

There's a LSL function llEdgeOfWorld. Used to detect if if you are near a sim edge. Here's a quote from The official documentation at wiki.secondlife.com:

integer llEdgeOfWorld( vector pos, vector dir );

Checks to see whether the border hit by dir from pos is the edge of the world (has no neighboring simulator)

Returns an integer that is a boolean.

Here's documentation from lslwiki.net, more precise, but same. Quote:

Returns TRUE if the line along the direction dir from the position pos hits the edge of the world in the current simulator. Returns FALSE if that line crosses into another simulator.

Simple enough. So, you think you can use this function, that if there's a neighboring sim, it returns true, else it returns false. WRONG!

For example, in following

llEdgeOfWorld( <128,128,0>, < 5, 0.0, 0.0>)

it checks 5 meters to the east of sim center. Clearly it's not sim edge, but it returns true. Here's the full code you can test:

// 2010-06-09
 default
 {
     state_entry()
     {
         if ( llEdgeOfWorld( <128,128,0>, < 5, 0.0, 0.0>))
         {
             llOwnerSay( "llEdgeOfWorld returned true" );
         } else
         {
             llOwnerSay( "llEdgeOfWorld returned false" );
         }
     }
 }

The correct documentation should be like this:

Returns TRUE if the line from pos to pos+dir crosses sim edge AND that the line do not pass at least 2 regions. Else, return FALSE.


Besides the incorrect documentation problem, the function is just idiotic. It should be as it is documented from the official site. So the problem is probably a sloppy implementation.

One can't imagine how simple things as this can get wrong. I doubt that the Linden Labs are filled with idiotic programers. Perhaps it is more caused by lack of time in startups.

Another interesting thing to test is how this function behaves when near a corner of a sim. There can be cases where the line lie in 3 squares where there might be regions, and the middle empty (i.e. part of the line does not lie in a region). Also, what happens if the line is so long such as 1000, such that the starting and ending position lies in regions but not the other parts. Stupid Linden Labs creating all these complexities.

Just about every technology associated with Second Life, the build system, the scripting language, the 3D viewer application, is filled with idiocies and bugs. Not sure how that happened. Part of it is of course due to the bleeding edge technology of virtual wold. But even that can't account for the vast number of incredible stupidities.

Thanks to Thundarr, who corrected me on this. Quote:

There is nothing wrong with the function, you are misunderstanding its use entirely.

llEdgeOfWorld( <128,128,0>, < 5, 0.0, 0.0>)

Does not check 5 meters east of the centre.

The second vector is a direction vector, not a position vector, so it checks a line from <128,128,0> at an angle specified by <5,0,0> (ie pointing due east). When this line hits the edge of the sim, it returns TRUE if there is no sim bordering at that point, and FALSE if there is a sim bordering at that intersection.

Though, to quibble a bit… it would be better if the second argument of the function is a degree. And or, that the documentation could made more clear.