Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Tool ? Find the exact size or range

Anastasia Serenity
Registered User
Join date: 2 Jan 2009
Posts: 53
09-18-2009 13:33
Is there a script that shows the exact distance of 2 prims and upades the info while moving - like a laser pointer?
thx
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-18-2009 16:41
There might be one somewhere, but it's easy to write something that would do the trick. Just off the top of my head....

Put something like this in one prim...

CODE

integer ON= FALSE;
default
{
state_entry()
{
llSetTimerEvent(3);
llListen(-9870,"","","");
}

touch_start(integer total_number)
{
if(ON)
{
llSetTimerEvent(3);
}
else
{
llSetTimerEvent(0);
}
ON = !ON;
}

listen(integer channel, string name, key id, string message)
{
float dist = llVecDist(llGetPos(),(vector)message);
llOwnerSay("Distance to object = " + (string)dist);
}

timer()
{
llRegionSay(-9880,"Hello");
}
}


and this in the other one ....

CODE

default
{
state_entry()
{
llListen(-9880,"","","Hello");
}

listen(integer channel, string name, key id, string message)
{
llRegionSay(-9870,(string)llGetPos());
}
}


Click the prim with the bigger script in it to start the process. Until you click it again, it will tell you every three seconds how far away the other prim is. It's not fancy. No bells and whistles, because this really is just off the top of my head.

ETA: BTW, the "distance" is the distance between the centers of the two prims in meters.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Anastasia Serenity
Registered User
Join date: 2 Jan 2009
Posts: 53
09-19-2009 05:53
Thank you so much and this is the tool I need and very useful when I create new SIMs and landscapes

Works very well!

Amazing!
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
09-19-2009 12:46
With a little more time to think about it, I've written a slightly more sophisticated version of the tool I posted earlier. It's still quite simple. It occurred to me, though, that it would be more helpful if the tool were activated by moving one of the two prims instead of having it mindlessly reporting the distance every few seconds, even if nothing had moved.

Here are updated and fully commented versions of the two scripts. As before, click on prim A to turn the tool on or off. First, the script for prim A .....

CODE

// Distance To ---- Rolig Loon --- 9/09
// This is a simple two-script tool for getting the distance
// between two prims if either one has been moved.
// Put this script in prim A and stand within chat distance
// while using the tool.
//
integer ON= FALSE;
default
{
state_entry()
{
llListen(-9870,"","",""); // Listen for position of prim B
}

moving_end() // If this prim has stopped moving ....
{
if(ON) // and if this device has been turned on ....
{
llRegionSay(-9880,"Hello"); // Ask prim B where it is.
}
}

touch_start(integer total_number)
{
if (llGetOwner() == llDetectedKey(0)) // If my owner has touched me ...
{
ON = !ON; // ... toggle this device on/off ...
llRegionSay(-9860,(string)ON); // ... and let prim B know.
if (ON)
{
llOwnerSay("Tool Activated"); // ... and the owner
}
else
{
llOwnerSay("Tool Deactivated");
}
}
}

listen(integer channel, string name, key id, string message)
{
float dist = llVecDist(llGetPos(),(vector)message); // Calculate the distance
// to prim B ...
llOwnerSay("Distance to object = " + (string)dist); // ... and tell the owner.
}
}


... and then the script for prim B ...

CODE

// Put this script in prim B.
//

integer ON;
default
{
state_entry()
{
llListen(-9880,"","","Hello"); // Listen for news that prim A has moved
llListen(-9860,"","",""); // Listen for a signal to turn this tool on/off
}

moving_end() // When this prim stops moving.....
{
if(ON) // ... if this tool has been turned on ....
{
llRegionSay(-9870,(string)llGetPos()); // ... report its position
}
}

listen(integer channel, string name, key id, string message)
{
if(channel == -9880) //If prim A reports that it has moved ...
{
llRegionSay(-9870,(string)llGetPos()); // ... report this prim's position
}
else if (channel == -9860) // If the owner has toggled the tool ON = !ON ..
{
ON = (integer)message; // ... update the toggle in this prim too.
}
}
}
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at