another GetSim function
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
07-11-2003 15:43
This script demonstrate the use of the llGetRegionCorner library call to identify the simulator region that the object is currently in. string getSimName() { string name; vector sim_corner = llGetRegionCorner();
if ( sim_corner.x == 254976 ) { if ( sim_corner.y == 256000 ) name = "Gibson"; else if ( sim_corner.y == 256256 ) name = "Bonifacio"; else if ( sim_corner.y == 256512 ) name = "Dore"; else if ( sim_corner.y == 256768 ) name = "Darkwood"; } else if ( sim_corner.x == 255232 ) { if ( sim_corner.y == 256000 ) name = "Oak Grove"; else if ( sim_corner.y == 256256 ) name = "Morris"; else if ( sim_corner.y == 256512 ) name = "Ahern"; else if ( sim_corner.y == 257792 ) name = "Brown"; else if ( sim_corner.y == 258048 ) name = "Argent"; } else if ( sim_corner.x == 255488 ) { if ( sim_corner.y == 256256 ) name = "Rizal"; else if ( sim_corner.y == 256512 ) name = "Lusk"; else if ( sim_corner.y == 257536 ) name = "Aqua"; else if ( sim_corner.y == 257792 ) name = "Green"; else if ( sim_corner.y == 258048 ) name = "Bisque"; } else if ( sim_corner.x == 255744 ) { if ( sim_corner.y == 256256 ) name = "Tehama"; else if ( sim_corner.y == 256512 ) name = "Perry"; else if ( sim_corner.y == 256768 ) name = "Kissling"; else if ( sim_corner.y == 257280 ) name = "Gray"; else if ( sim_corner.y == 257536 ) name = "Blue"; else if ( sim_corner.y == 257792 ) name = "Mauve"; else if ( sim_corner.y == 258048 ) name = "Chartreuse"; } else if ( sim_corner.x == 256000 ) { if ( sim_corner.y == 256000 ) name = "Da Boom"; else if ( sim_corner.y == 256256 ) name = "Freelon"; else if ( sim_corner.y == 256512 ) name = "Clara"; else if ( sim_corner.y == 256768 ) name = "Boardman"; else if ( sim_corner.y == 257024 ) name = "Tan"; else if ( sim_corner.y == 257280 ) name = "Plum"; else if ( sim_corner.y == 257536 ) name = "Lime"; else if ( sim_corner.y == 257792 ) name = "Mocha"; else if ( sim_corner.y == 258048 ) name = "Crimson"; } else if ( sim_corner.x == 256256 ) { if ( sim_corner.y == 255744 ) name = "Immaculate"; else if ( sim_corner.y == 256000 ) name = "Ritch"; else if ( sim_corner.y == 256256 ) name = "Minna"; else if ( sim_corner.y == 256512 ) name = "Varney"; else if ( sim_corner.y == 256768 ) name = "DeHaro"; else if ( sim_corner.y == 257280 ) name = "Sage"; else if ( sim_corner.y == 257536 ) name = "Rose"; else if ( sim_corner.y == 257792 ) name = "Olive"; else if ( sim_corner.y == 258048 ) name = "Indigo"; } else if ( sim_corner.x == 256512 ) { if ( sim_corner.y == 256000 ) name = "Zoe"; else if ( sim_corner.y == 256256 ) name = "Natoma"; else if ( sim_corner.y == 256512 ) name = "Stillman"; else if ( sim_corner.y == 257536 ) name = "Teal"; else if ( sim_corner.y == 257792 ) name = "Slate"; else if ( sim_corner.y == 258048 ) name = "Magenta"; } else if ( sim_corner.x == 256768 ) { if ( sim_corner.y == 256000 ) name = "Clementina"; else if ( sim_corner.y == 256256 ) name = "Taber"; else if ( sim_corner.y == 258048 ) name = "Maroon"; } else if ( sim_corner.x == 257024 ) { if ( sim_corner.y == 256256 ) name = "Welsh"; else if ( sim_corner.y == 258048 ) name = "Periwinkle"; } else if ( sim_corner.x == 257280 ) { if ( sim_corner.y == 256000 ) name = "Jessie"; else if ( sim_corner.y == 256256 ) name = "Clyde"; else if ( sim_corner.y == 257792 ) name = "Umber"; else if ( sim_corner.y == 258048 ) name = "Purple"; } else if ( sim_corner.x == 257536 ) { if ( sim_corner.y == 256000 ) name = "Stanford"; else if ( sim_corner.y == 256256 ) name = "Hawthorne"; } else if ( sim_corner.x == 257792 ) { if ( sim_corner.y == 256000 ) name = "Federal"; else if ( sim_corner.y == 256256 ) name = "Shipley"; }
return name; }
default { touch_start( integer total_number ) { llWhisper( 0, getSimName() ); } }
|
Ope Rand
Alien
Join date: 14 Mar 2003
Posts: 352
|
07-12-2003 03:42
wow! i didn't know there was a llGetRegionCorner(). man what else am i missing... oh and GJ Jake 
_____________________
-OpeRand
|
Bino Arbuckle
Registered User
Join date: 31 Dec 2002
Posts: 369
|
07-13-2003 16:56
Jake, cool function. However, might I suggest you use an X and Y constant with an offset so this can be more easily extended when the grid is expanded in the future?
I mean, we know that all sims are 256x256. So it's a simple matter of taking a current x,y coord and adding an offset of a multiple of 256.
Tis a thought.
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
07-13-2003 17:58
The llGetRegionCorner library call was mentioned in the following thread: /invalid_link.htmlThe only other call you might have missed is llWater, which is not nearly as interesting. Both of these will appear in the next release of the LSL help file.
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-14-2003 00:07
Excellant! Ty vm for posting this! Theres one problem though... Returning strings from functions eventually gives yah a stack heap collision (Darn list2leak and string2leak  ) -Chris
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
07-14-2003 06:17
could make name a global variable maybe... i.e. anyone know if it is the return that is causing the stack-heap explosion?
_____________________
i've got nothing. 
|
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
|
07-14-2003 06:58
Yes nada that would fix it. It is specifically returning a string or list from a function that results in a stack heap collision.
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
07-14-2003 18:30
I'm not thrilled with using a global variable for something like this, but until the memory leak is fixed, I suppose it's reasonable. Here's a version that uses offsets from the global origin. string simName;
setSimName() { integer SIM_WIDTH = 256; integer SIM_HEIGHT = 256; vector sim_corner = llGetRegionCorner();
if ( sim_corner.x == SIM_WIDTH * 996 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Gibson"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Bonifacio"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Dore"; else if ( sim_corner.y == SIM_HEIGHT * 1003 ) simName = "Darkwood"; } else if ( sim_corner.x == SIM_WIDTH * 997 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Oak Grove"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Morris"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Ahern"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Brown"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Argent"; } else if ( sim_corner.x == SIM_WIDTH * 998 ) { if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Rizal"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Lusk"; else if ( sim_corner.y == SIM_HEIGHT * 1006 ) simName = "Aqua"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Green"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Bisque"; } else if ( sim_corner.x == SIM_WIDTH * 999 ) { if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Tehama"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Perry"; else if ( sim_corner.y == SIM_HEIGHT * 1003 ) simName = "Kissling"; else if ( sim_corner.y == SIM_HEIGHT * 1005 ) simName = "Gray"; else if ( sim_corner.y == SIM_HEIGHT * 1006 ) simName = "Blue"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Mauve"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Chartreuse"; } else if ( sim_corner.x == SIM_WIDTH * 1000 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Da Boom"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Freelon"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Clara"; else if ( sim_corner.y == SIM_HEIGHT * 1003 ) simName = "Boardman"; else if ( sim_corner.y == SIM_HEIGHT * 1004 ) simName = "Tan"; else if ( sim_corner.y == SIM_HEIGHT * 1005 ) simName = "Plum"; else if ( sim_corner.y == SIM_HEIGHT * 1006 ) simName = "Lime"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Mocha"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Crimson"; } else if ( sim_corner.x == SIM_WIDTH * 1001 ) { if ( sim_corner.y == SIM_HEIGHT * 999 ) simName = "Immaculate"; else if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Ritch"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Minna"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Varney"; else if ( sim_corner.y == SIM_HEIGHT * 1003 ) simName = "DeHaro"; else if ( sim_corner.y == SIM_HEIGHT * 1005 ) simName = "Sage"; else if ( sim_corner.y == SIM_HEIGHT * 1006 ) simName = "Rose"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Olive"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Indigo"; } else if ( sim_corner.x == SIM_WIDTH * 1002 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Zoe"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Natoma"; else if ( sim_corner.y == SIM_HEIGHT * 1002 ) simName = "Stillman"; else if ( sim_corner.y == SIM_HEIGHT * 1006 ) simName = "Teal"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Slate"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Magenta"; } else if ( sim_corner.x == SIM_WIDTH * 1003 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Clementina"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Taber"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Maroon"; } else if ( sim_corner.x == SIM_WIDTH * 1004 ) { if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Welsh"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Periwinkle"; } else if ( sim_corner.x == SIM_WIDTH * 1005 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Jessie"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Clyde"; else if ( sim_corner.y == SIM_HEIGHT * 1007 ) simName = "Umber"; else if ( sim_corner.y == SIM_HEIGHT * 1008 ) simName = "Purple"; } else if ( sim_corner.x == SIM_WIDTH * 1006 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Stanford"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Hawthorne"; } else if ( sim_corner.x == SIM_WIDTH * 1007 ) { if ( sim_corner.y == SIM_HEIGHT * 1000 ) simName = "Federal"; else if ( sim_corner.y == SIM_HEIGHT * 1001 ) simName = "Shipley"; } }
default { touch_start( integer total_number ) { setSimName(); llWhisper( 0, simName ); } }
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
07-15-2003 07:54
hmm i think that for the moment sim widths and lengths are fixed, so it makes more sense to me to divide the whole vector by 256, and then compare those results, rather than multiplying each one, in every statement. string simName;
setSimName() { vector sim_corner = llGetRegionCorner()/256;
if ( sim_corner.x == 996 ) { if ( sim_corner.y == 1000 ) simName = "Gibson"; else if ( sim_corner.y == 1001 ) simName = "Bonifacio"; else if ( sim_corner.y == 1002 ) simName = "Dore"; else if ( sim_corner.y == 1003 ) simName = "Darkwood"; } else if ( sim_corner.x == 997 ) { if ( sim_corner.y == 1000 ) simName = "Oak Grove"; else if ( sim_corner.y == 1001 ) simName = "Morris"; else if ( sim_corner.y == 1002 ) simName = "Ahern"; else if ( sim_corner.y == 1007 ) simName = "Brown"; else if ( sim_corner.y == 1008 ) simName = "Argent"; } else if ( sim_corner.x == 998 ) { if ( sim_corner.y == 1001 ) simName = "Rizal"; else if ( sim_corner.y == 1002 ) simName = "Lusk"; else if ( sim_corner.y == 1006 ) simName = "Aqua"; else if ( sim_corner.y == 1007 ) simName = "Green"; else if ( sim_corner.y == 1008 ) simName = "Bisque"; } else if ( sim_corner.x == 999 ) { if ( sim_corner.y == 1001 ) simName = "Tehama"; else if ( sim_corner.y == 1002 ) simName = "Perry"; else if ( sim_corner.y == 1003 ) simName = "Kissling"; else if ( sim_corner.y == 1005 ) simName = "Gray"; else if ( sim_corner.y == 1006 ) simName = "Blue"; else if ( sim_corner.y == 1007 ) simName = "Mauve"; else if ( sim_corner.y == 1008 ) simName = "Chartreuse"; } else if ( sim_corner.x == 1000 ) { if ( sim_corner.y == 1000 ) simName = "Da Boom"; else if ( sim_corner.y == 1001 ) simName = "Freelon"; else if ( sim_corner.y == 1002 ) simName = "Clara"; else if ( sim_corner.y == 1003 ) simName = "Boardman"; else if ( sim_corner.y == 1004 ) simName = "Tan"; else if ( sim_corner.y == 1005 ) simName = "Plum"; else if ( sim_corner.y == 1006 ) simName = "Lime"; else if ( sim_corner.y == 1007 ) simName = "Mocha"; else if ( sim_corner.y == 1008 ) simName = "Crimson"; } else if ( sim_corner.x == 1001 ) { if ( sim_corner.y == 999 ) simName = "Immaculate"; else if ( sim_corner.y == 1000 ) simName = "Ritch"; else if ( sim_corner.y == 1001 ) simName = "Minna"; else if ( sim_corner.y == 1002 ) simName = "Varney"; else if ( sim_corner.y == 1003 ) simName = "DeHaro"; else if ( sim_corner.y == 1005 ) simName = "Sage"; else if ( sim_corner.y == 1006 ) simName = "Rose"; else if ( sim_corner.y == 1007 ) simName = "Olive"; else if ( sim_corner.y == 1008 ) simName = "Indigo"; } else if ( sim_corner.x == 1002 ) { if ( sim_corner.y == 1000 ) simName = "Zoe"; else if ( sim_corner.y == 1001 ) simName = "Natoma"; else if ( sim_corner.y == 1002 ) simName = "Stillman"; else if ( sim_corner.y == 1006 ) simName = "Teal"; else if ( sim_corner.y == 1007 ) simName = "Slate"; else if ( sim_corner.y == 1008 ) simName = "Magenta"; } else if ( sim_corner.x == 1003 ) { if ( sim_corner.y == 1000 ) simName = "Clementina"; else if ( sim_corner.y == 1001 ) simName = "Taber"; else if ( sim_corner.y == 1008 ) simName = "Maroon"; } else if ( sim_corner.x == 1004 ) { if ( sim_corner.y == 1001 ) simName = "Welsh"; else if ( sim_corner.y == 1008 ) simName = "Periwinkle"; } else if ( sim_corner.x == 1005 ) { if ( sim_corner.y == 1000 ) simName = "Jessie"; else if ( sim_corner.y == 1001 ) simName = "Clyde"; else if ( sim_corner.y == 1007 ) simName = "Umber"; else if ( sim_corner.y == 1008 ) simName = "Purple"; } else if ( sim_corner.x == 1006 ) { if ( sim_corner.y == 1000 ) simName = "Stanford"; else if ( sim_corner.y == 1001 ) simName = "Hawthorne"; } else if ( sim_corner.x == 1007 ) { if ( sim_corner.y == 1000 ) simName = "Federal"; else if ( sim_corner.y == 1001 ) simName = "Shipley"; } }
default { touch_start( integer total_number ) { setSimName(); llWhisper( 0, simName ); } }
_____________________
i've got nothing. 
|
Goodwill Epoch
Admiral of Kazenojin
Join date: 20 May 2003
Posts: 121
|
07-15-2003 11:05
Might I reccomend another modification to this to simplify it? Place each sim and its Coords into a list I.E. list sims = [996, 1000, "Gibson", 996, 1001, "Bonifacio", .... ]
And use a loop to check sim position. Then still use a return, but return an integer that corresponds to the position in the list of the name. This would also allow you to very simply add sims by their coords instead of putting in another if/else.
_____________________
http://www.narfy.com
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
07-15-2003 11:10
To make the global variable more reliable, you could also do something like this: (Nada, credit to you, Im using your function as an example) string simName;
integer setSimName() { vector sim_corner = llGetRegionCorner()/256;
if ( sim_corner.x == 996 ) { if ( sim_corner.y == 1000 ) simName = "Gibson"; else if ( sim_corner.y == 1001 ) simName = "Bonifacio"; else if ( sim_corner.y == 1002 ) simName = "Dore"; else if ( sim_corner.y == 1003 ) simName = "Darkwood"; } else if ( sim_corner.x == 997 ) { if ( sim_corner.y == 1000 ) simName = "Oak Grove"; else if ( sim_corner.y == 1001 ) simName = "Morris"; else if ( sim_corner.y == 1002 ) simName = "Ahern"; else if ( sim_corner.y == 1007 ) simName = "Brown"; else if ( sim_corner.y == 1008 ) simName = "Argent"; } else if ( sim_corner.x == 998 ) { if ( sim_corner.y == 1001 ) simName = "Rizal"; else if ( sim_corner.y == 1002 ) simName = "Lusk"; else if ( sim_corner.y == 1006 ) simName = "Aqua"; else if ( sim_corner.y == 1007 ) simName = "Green"; else if ( sim_corner.y == 1008 ) simName = "Bisque"; } else if ( sim_corner.x == 999 ) { if ( sim_corner.y == 1001 ) simName = "Tehama"; else if ( sim_corner.y == 1002 ) simName = "Perry"; else if ( sim_corner.y == 1003 ) simName = "Kissling"; else if ( sim_corner.y == 1005 ) simName = "Gray"; else if ( sim_corner.y == 1006 ) simName = "Blue"; else if ( sim_corner.y == 1007 ) simName = "Mauve"; else if ( sim_corner.y == 1008 ) simName = "Chartreuse"; } else if ( sim_corner.x == 1000 ) { if ( sim_corner.y == 1000 ) simName = "Da Boom"; else if ( sim_corner.y == 1001 ) simName = "Freelon"; else if ( sim_corner.y == 1002 ) simName = "Clara"; else if ( sim_corner.y == 1003 ) simName = "Boardman"; else if ( sim_corner.y == 1004 ) simName = "Tan"; else if ( sim_corner.y == 1005 ) simName = "Plum"; else if ( sim_corner.y == 1006 ) simName = "Lime"; else if ( sim_corner.y == 1007 ) simName = "Mocha"; else if ( sim_corner.y == 1008 ) simName = "Crimson"; } else if ( sim_corner.x == 1001 ) { if ( sim_corner.y == 999 ) simName = "Immaculate"; else if ( sim_corner.y == 1000 ) simName = "Ritch"; else if ( sim_corner.y == 1001 ) simName = "Minna"; else if ( sim_corner.y == 1002 ) simName = "Varney"; else if ( sim_corner.y == 1003 ) simName = "DeHaro"; else if ( sim_corner.y == 1005 ) simName = "Sage"; else if ( sim_corner.y == 1006 ) simName = "Rose"; else if ( sim_corner.y == 1007 ) simName = "Olive"; else if ( sim_corner.y == 1008 ) simName = "Indigo"; } else if ( sim_corner.x == 1002 ) { if ( sim_corner.y == 1000 ) simName = "Zoe"; else if ( sim_corner.y == 1001 ) simName = "Natoma"; else if ( sim_corner.y == 1002 ) simName = "Stillman"; else if ( sim_corner.y == 1006 ) simName = "Teal"; else if ( sim_corner.y == 1007 ) simName = "Slate"; else if ( sim_corner.y == 1008 ) simName = "Magenta"; } else if ( sim_corner.x == 1003 ) { if ( sim_corner.y == 1000 ) simName = "Clementina"; else if ( sim_corner.y == 1001 ) simName = "Taber"; else if ( sim_corner.y == 1008 ) simName = "Maroon"; } else if ( sim_corner.x == 1004 ) { if ( sim_corner.y == 1001 ) simName = "Welsh"; else if ( sim_corner.y == 1008 ) simName = "Periwinkle"; } else if ( sim_corner.x == 1005 ) { if ( sim_corner.y == 1000 ) simName = "Jessie"; else if ( sim_corner.y == 1001 ) simName = "Clyde"; else if ( sim_corner.y == 1007 ) simName = "Umber"; else if ( sim_corner.y == 1008 ) simName = "Purple"; } else if ( sim_corner.x == 1006 ) { if ( sim_corner.y == 1000 ) simName = "Stanford"; else if ( sim_corner.y == 1001 ) simName = "Hawthorne"; } else if ( sim_corner.x == 1007 ) { if ( sim_corner.y == 1000 ) simName = "Federal"; else if ( sim_corner.y == 1001 ) simName = "Shipley"; } return TRUE; }
default { touch_start( integer total_number ) { if(setSimName()); llWhisper( 0, simName ); //Or if(setSimName()) llWhisper(0,simName); } }
This way, you know the global variable has a new value from the function before using the value it contains. (makes calling the function more secore IMO, if not, it still looks good on paper  and if a sim hiccups during the procedure (ex. the llSay being called before the function finishes it's process), the script wont hiccup as loudly) -Chris
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
07-15-2003 16:44
From: someone Originally posted by Goodwill Epoch Might I reccomend another modification to this to simplify it? Place each sim and its Coords into a list I.E.
list sims = [996, 1000, "Gibson", 996, 1001, "Bonifacio", .... ]
And use a loop to check sim position. Then still use a return, but return an integer that corresponds to the position in the list of the name.
This would also allow you to very simply add sims by their coords instead of putting in another if/else. wouldn't even need a for loop, you could just use the llListFindList([x,y]); then offset the returned integer by the appropriate amount to get the name. edit- i have no idea how often this script would run into the dread stack heap collision, or if it would at all for that matter.
_____________________
i've got nothing. 
|
Goodwill Epoch
Admiral of Kazenojin
Join date: 20 May 2003
Posts: 121
|
07-15-2003 18:21
Well, your not returning a list or a string, just an integer. Does the llListFindList generate stack/heap collision errors? Considering this, we've pretty much rewritten the get sim function into a long list and two lines of code  vector cur_sim = llGetRegionCorner(); string sim = llList2String(sims, (llListFindList(sims, [cur_sim.x, cur_sim.y]) + 1));
_____________________
http://www.narfy.com
|
kohne Kato
Woo. Yay.
Join date: 4 May 2003
Posts: 109
|
07-15-2003 20:48
Before I'm beat to the punch, since you guys are going where I went this morning, let me post a solution that eventually boils down to six lines of code. (I can post them later.) The results of llGetRegionCorner() are indeed divisible by 256. So we divide them by 256 and get a three or four digit number. But what if we subtract 1000? We get a vector, the first two numbers of which are INTEGERS between -10 and 10. Then we put together a string: /7:-3  live,Slate,etc /6:-2:Blah,Blah In the function we get the simplified form of llGetRegionCorner, look up "/y:" in the string, and from the end of that string, take a slice up to the next "/". This gives us a string that can be parsed by ":" and ",". The 0th item in that list is the offset. That is, the simplified X at which the row of names begins. We use that and the simplified x to get which item in the string to return, and we're set to go. It's fast, there's little code, and there's no lengthy "if" statements to complicate the matter when the Lindens add new sims. You simply slip in a new row on the string.
|
kohne Kato
Woo. Yay.
Join date: 4 May 2003
Posts: 109
|
5-line, 1-string solution to the GetSim() problem
07-15-2003 20:56
string world_map=" /7:-3,Brown,Green,Mauve,Mocha,Olive,Slate, /6:-2,Aqua,Blue,Lime,Rose,Teal, /5:-1,Grey,Plum,Sage, /4:+0,Tan, /3:-4,Darkwood,,,Kissling,Boardman,DeHaro, /2:-4,Dore,Ahern,Lusk,Perry,Clara,Varney,Stillman, /1:-4,Bonifacio,Morris,Rizal,Tehama,Freelon,Mina,Natoma,Taber,Welsh,Clyde,Hawthorn,Shipman, /0:-4,Gibson,Oak Grove,,,Da Boom,Ritch,Zoe,Clementina,,Jessie,Stanford,Federal, /-1:1,Immaculate";
string GetSim () { vector rel=(llGetRegionCorner()/256)-<1000,1000,0>; // gets the relative coordinates of the sim string begTerm="/"+(string)((integer)rel.y)+":"; // what will we be looking for? integer begSlice=llStringLength(begTerm)+llSubStringIndex(world_map,begTerm); // where's the beginning of the slice? list Slice=llParseString2List(llGetSubString(world_map,begSlice,-1+begSlice+llSubStringIndex(llGetSubString(world_map,begSlice,-1),"/")),[","],[]); // get the slice return llList2String(Slice,(integer)rel.x - (integer)llList2String(Slice,0) + 1); // use the offset and rel.x to return the appropriate string } // and she does the GetSim victory dance! And the crowd goes wild! Sssssss!
|
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
|
07-16-2003 06:29
kohne, your function does even more work than the jake's first one... so although i think it is quite elegant, unless this one has a problem with a list leak, i think i would just stick with the big list that you use llListFindList in. string sim_name;
list sims=[Gibson,996,1000, Bonifacio,996,1001, Dore,996,1002, Darkwood,996,1003,
Oak Grove,997,1000, Morris,997,1001, Ahern,997,1002, Brown,997,1007, Argent,997,1008,
Rizal,998,1001, Lusk,998,1002, Aqua,998,1006, Green,998,1007, Bisque,998,1008,
Tehama,999,1001, Perry,999,1002, Kissling,999,1003, Gray,999,1005, Blue,999,1006, Mauve,999,1007, Chartreuse,999,1008,
Da Boom,1000,1000, Freelon,1000,1001, Clara,1000,1002, Boardman,1000,1003 Tan,1000,1004, Plum,1000,1005, Lime,1000,1006, Mocha,1000,1007, Crimson,1000,1008
Immaculate,1001,999, Ritch,1001,1000, Minna,1001,1001, Varney,1001,1002, DeHaro,1001,1003, Sage,1001,1005, Rose,1001,1006, Olive,1001,1007, Indigo,1001,1008,
Zoe,1002,1000, Natoma,1002,1001, Stillman,1002,1002, Teal,1002,1006, Slate,1002,1007, Magenta,1002,1008,
Clementina,1003,1000, Taber,1003,1001, Maroon,1003,1008,
Welsh,1004,1001, Periwinkle,1004,1008,
Jessie,1005,1000, Clyde,1005,1001, Umber,1005,1007, Purple,1005,1008,
Stanford,1006,1000, Hawthorne,1006,1001,
Federal,1007,1000, Shipley,1007,1001,];
getSim() { vector sim_corner = llGetRegionCorner()/256; sim_name=llList2String(sims,(llListFindList(sims,[sim_corner.x,sim_corner.y]) - 1)); }
btw this is untested.
_____________________
i've got nothing. 
|
Jake Cellardoor
CHM builder
Join date: 27 Mar 2003
Posts: 528
|
07-16-2003 10:30
From: someone Originally posted by Nada Epoch kohne, your function does even more work than the jake's first one... "Even more work"? I think my original version was probably the fastest of the variants posted so far. It was just a series of comparisons, with no arithmetic whatsoever. Your version where you divide by 256 adds an arithmetic operation, so it technically does "more work." The use of the various llList* increase the amount of work done -- they perform even more comparisons (since they're not skipping rows), and have other, unknown overhead as well. What we're getting into now is the tradeoff between readability/maintainability, code size, and performance. It's generallly impossible to optimize all of them; you have to pick which one is most important to you.
|
kohne Kato
Woo. Yay.
Join date: 4 May 2003
Posts: 109
|
07-16-2003 10:37
Wow. This is why I love SL. I can take a lengthy problem and boil it down to a few lines, and before I even get a chance to post it (and do my little victory dance!) someone has found a solution one hundred times more elegant! Very nice solution! I still can't believe I left the thing as a string... could be 'cause I hate dealing with lists in LSL. Though I'd still subtract <1000,1000,0> from each coordinate pair just to cut down on those long numbers. And shouldn't there be quotes around each of those strings? string sim_name;
// list sims data is <str name,integer rel.x,integer rel.y,> list sims = [ "Gibson",-4,0, "Bonifacio",-4,1, "Dore",-4,2, "Darkwood",-4,3,
"Oak Grove",-3,0, "Morris",-3,1, "Ahern",-3,2, "Brown",-3,7, "Argent",-3,8,
"Rizal",-2,1, "Lusk",-2,2, "Aqua",-2,6, "Green",-2,7, "Bisque",-2,8,
"Tehama",-1,1, "Perry",-1,2, "Kissling",-1,3, "Gray",-1,5, "Blue",-1,6, "Mauve",-1,7, "Chartreuse",-1,8,
"Da Boom",0,0, "Freelon",0,1, "Clara",0,2, "Boardman",0,3 "Tan",0,4, "Plum",0,5, "Lime",0,6, "Mocha",0,7, "Crimson",0,8
"Immaculate",1,-1, "Ritch",1,0, "Minna",1,1, "Varney",1,2, "DeHaro",1,3, "Sage",1,5, "Rose",1,6, "Olive",1,7, "Indigo",1,8,
"Zoe",2,0, "Natoma",2,1, "Stillman",2,2, "Teal",2,6, "Slate",2,7, "Magenta",2,8,
"Clementina",3,0, "Taber",3,1, "Maroon",3,8,
"Welsh",4,1, "Periwinkle",4,8,
"Jessie",5,0, "Clyde",5,1, "Umber",5,7, "Purple",5,8,
"Stanford",6,0, "Hawthorne",6,1,
"Federal",7,0, "Shipley",7,1];
getSim() { vector sim_corner = (llGetRegionCorner() / 256) - <1000,1000,0>; sim_name = llList2String(sims,(llListFindList(sims,[sim_corner.x,sim_corner.y] ) - 1));}
|
Jsecure Hanks
Capitalist
Join date: 9 Dec 2003
Posts: 1,451
|
05-20-2004 18:03
For anyone else reading this, note that none of the above solutions matter anymore.
You now have:
string llGetRegionName(void)
so the following:
llGetRegionName();
returns a string with the name of the sim the script is in. Job done.
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
05-31-2004 16:37
Not true, Say you want the name of the next sim over? Or you want to know which sim a landmark is in. This is still usefull.
_____________________
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
|
Jsecure Hanks
Capitalist
Join date: 9 Dec 2003
Posts: 1,451
|
06-01-2004 08:33
I guess so... Mind you I can't see this ever coming up for anything I have on the radar for the next... Long time...
|
Deklax Fairplay
Black Sun
Join date: 2 Jul 2004
Posts: 357
|
10-10-2004 21:55
this was very useful to me =) w00t
|