Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripts and Notecard to Translate "World Coordinates<->Sim Names"

Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-23-2004 06:54
Bellow are two scripts and one notecard I use to translate "World Coordinates"<->"Sim Names" in my Touring Hot Air Balloon. I hope that the Lindens provide a native LSL solution for this in the future.

I recently had to split the script into two parts, because one single script cannot store all of the information for all approximately 185 public sims with the limited memory we have.

These scripts work by receiving a Linked Message from some other script in the form of a World Coordinate vector or a string representing the name of a sim. It will then return back the sim name or World Coordinate, respectively.

Script #1
============
CODE

//Region Database Script
//by Hank Ramos
//June 22, 2004
list Regions;
integer RegionLineCount;
integer NotifyCount;
key RegionReadKey;

disp(string m)
{
//Send Message to Display on Overhead Text display
llMessageLinked(LINK_SET, 411, m, NULL_KEY);
}
getRegionName(vector RegionCorner)
{
string ResultString;

vector sim_corner = (RegionCorner / 256) - <1000,1000,0>;

integer XValue = (integer)sim_corner.x;
integer YValue = (integer)sim_corner.y;

//Send coordinates to Coord Script for processing
llMessageLinked(llGetLinkNumber(), 649500, (string)XValue + "," + (string)YValue, NULL_KEY);
}

getRegionVector(string name)
{
integer ListIndex = llListFindList(Regions, [name]);
if (ListIndex >= 0)
{
//Send position of region name in list to other script
llMessageLinked(llGetLinkNumber(), 649000, (string)ListIndex, NULL_KEY);

}
else
{
disp("Region " + name + " not found in database.");
}
}

default
{
state_entry()
{
disp("Loading Regions...");
Regions = [];
RegionLineCount = 0;
llResetOtherScript("Region Coords Script");
RegionReadKey = llGetNotecardLine("Regions", 0);
}

link_message(integer sn, integer n, string m, key id)
{
string tempString;
vector tempVector;
list tempList;

m = llToLower(m);
if (n == 100)
{
//Convert Name to Vector
getRegionVector(m);
return;
}
if (n == 101)
{
//Convert Vector to Name
getRegionName((vector)m);
return;
}
if (n == 102)
{
//Retrieve region name of current sim.
getRegionName(llGetRegionCorner());
return;
}

if (n == 649001)
{
//Coordinates coming back
tempList = llCSV2List(m);
tempVector = <llList2Float(tempList,0),llList2Float(tempList,1),0>;
tempVector = (tempVector + <1000,1000,0>)* 256;
//Send region coordinates back to requestor
llMessageLinked(llGetLinkNumber(), 200, (string)tempVector, NULL_KEY);
}
if (n == 649501)
{
//Index of Region Name in list coming back
tempString = llList2String(Regions, (integer)m);
//Send region name back to requestor
llMessageLinked(llGetLinkNumber(), 201, tempString, NULL_KEY);
}
if (n == 999)
{
llResetScript();
}
if (n == 95562)
{
if ((m == "reset regions")||(m == "reset notecards"))
{
llResetScript();
}
}

}

dataserver(key requested, string data)
{
//Process Regions
if (requested == RegionReadKey)
{
list L = llCSV2List(data);
if (data != EOF)
{
if ((llSubStringIndex(data, "#") != 0) && (llGetListLength(L) == 3))
{
Regions += [llToLower(llList2String(L, 0))];
//Send Region Coordinates to other script (due to memory limitations with so many sims)
llMessageLinked(llGetLinkNumber(), 648000, llList2String(L, 1) + "," + llList2String(L, 2), NULL_KEY);
}
RegionLineCount += 1;
NotifyCount += 1;
if (NotifyCount > 10)
{
disp((string)llGetListLength(Regions) + " Regions Loaded");
NotifyCount = 0;
}
RegionReadKey = llGetNotecardLine("Regions", RegionLineCount);
}
else
{
llMessageLinked(0, 102, "", NULL_KEY);
disp("Region Load Complete. Total " + (string)llGetListLength(Regions) + " Regions Loaded");
llMessageLinked(LINK_SET, 203, (string)llGetListLength(Regions), NULL_KEY);
}
L = [];
}

}
}

============

Script #2
This script was added to provide more storage space in
memory. It only keeps a parallel script with the world coordinates
of each simulator.
============
CODE

//Region Database Coords Script
//by Hank Ramos
//June 22, 2004
list RegionCoords;

disp(string m)
{
llMessageLinked(LINK_SET, 411, m, NULL_KEY);
}

default
{
state_entry()
{
RegionCoords = [];
}

link_message(integer sn, integer n, string m, key id)
{
if (n == 648000)
{
//Add region coords to list
RegionCoords += m;
return;
}
if (n == 649000)
{
//Send back region coordinates for requested list index.
llMessageLinked(llGetLinkNumber(), 649001, llList2String(RegionCoords, (integer)m), NULL_KEY);
return;
}
if (n == 649500)
{
//Find region coordinates in list, and pass back list index
integer ListIndex = llListFindList(RegionCoords,[m]);
if (ListIndex >= 0)
{
llMessageLinked(llGetLinkNumber(), 649501, (string)ListIndex, NULL_KEY);
};

}
}
}

============

The notecard with the sim locations is an attachment to the next message.
_____________________
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-23-2004 09:06
Here is the in-world notecard that contains all the sim names and world coordinates.
_____________________
Cadroe Murphy
Assistant to Mr. Shatner
Join date: 31 Jul 2003
Posts: 689
06-23-2004 10:09
Thanks, Hank, that's awesome! I'm guessing you won't mind if I post this sim data in another form on the web for anyone to use?
_____________________
ShapeGen 1.12 and Cadroe Lathe 1.32 now available through
SLExchange.
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-23-2004 10:14
Not a problem, the data is open and freely available anyways. The region coordinates in the notecard aren't actual world coordinates, but are calculated in the script to useful coordinates for LSL functions. However, they are much easier to update in their current format.
_____________________
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-23-2004 10:19
Here is a link to a Feature Suggestion to have LL provide us with 2 LSL functions to replace the hard-to-maintain and slow scripts that are necessary above.

/13/dc/16031/1.html
_____________________
Cadroe Murphy
Assistant to Mr. Shatner
Join date: 31 Jul 2003
Posts: 689
06-23-2004 10:29
The coordinates in the notecard are in the form I'd want anyway. My primary interest is in the sims' positions relative to one another. But I can convert them if I need to.
_____________________
ShapeGen 1.12 and Cadroe Lathe 1.32 now available through
SLExchange.
Cadroe Murphy
Assistant to Mr. Shatner
Join date: 31 Jul 2003
Posts: 689
06-23-2004 13:33
Hank - FYI, the data for "fame" on line 149 has a period instead of a comma as a seperator.
_____________________
ShapeGen 1.12 and Cadroe Lathe 1.32 now available through
SLExchange.
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-23-2004 14:29
From: someone
Originally posted by Cadroe Murphy
Hank - FYI, the data for "fame" on line 149 has a period instead of a comma as a seperator.


Thanks, I'll fix in my next balloon update.
_____________________
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
06-24-2004 03:01
if you wanted to save one integer spot in list you could combine the two integers. treat them as 15 bit integers; the negative bit would be a bit of a pain but workable. thats what i've done in my code but then i'm not working with negative numbers and if there were any it would break (guess i should fix that) (i'm using only 3 bits for each integer so i can get 10 total inside, it's in the addflag function and the extractor is in "if(r>0)" of the main function).

something like
CODE

integer d=( x + 16384 ) + 32768 * ( y + 16384 );
integer xa= (d & 32767) - 16384;
integer ya= ((d / 32768) & 32767) - 16384;

i'm amazed your storing the coords in strings...
*starts working on a hacked version*
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
06-24-2004 07:03
The reason the notecard is the way it is, is to make it easy for people to update, just in case I ever leave SL.

However, you are right, the coordinates could be more efficiently stored in the internal lists by encoding them into a single integer.

I'll work on a newer version to do just that. But, I'll still keep the lists separate as we will definately need the memory capacity in the future to store more and more sims as they come online.
_____________________
Cadroe Murphy
Assistant to Mr. Shatner
Join date: 31 Jul 2003
Posts: 689
06-24-2004 07:18
If they implement out-bound RPC, we can also avoid these memory issues that way. This data is large only by the standards of SL scripts. I attached an XML file with the sim coords (as a .txt cause the forum don't like .xml). It's 10K. Heck, that would have fit nicely on my Commodore 64 :)
_____________________
ShapeGen 1.12 and Cadroe Lathe 1.32 now available through
SLExchange.