Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Notecard Reader Fast_Find_Lines_in_a_Notecard  

Fast_Find_Lines_in_a_Notecard

There is an LL function that does this now:
llGetNumberOfNotecardLines

This is a fast way to find the number of lines in a notecard. It is fast as is, and can be adjusted to be faster if you have an idea about the notecards you will be getting the size of. This is an implementation of a binary search.

Category: Notecard Reader
By : AmaOmega
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Fast_Find_Lines_in_a_Notecard
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Fast_Find_Lines_in_a_Notecard_1.lsl
1 // Made by Ama Omega
2 // Version 1.1
3
4 // Adjust these two values for your notecards:
5
6 // A Higher START_INC will be faster if
7 // you have a large range of possible card lengths
8 // A Lower START_INC will be faster if
9 // you have a small range of possible card lengths
10 // This needs to be less than START_LINE
11 integer START_INC = 10;
12
13 // This should be set to your average note card length.
14 integer START_LINE = 20;
15
16 // Below is the actual code.
17 integer inc;
18 integer line;
19 string name;
20 key request;
21
22 default
23 {
25 {
26 inc = START_INC;
27 line = START_LINE;
28 }
29
30 changed(integer total_number)
31 {
32 inc = START_INC;
33 line = START_LINE;
34
36 request = llGetNotecardLine(name,line);
37 }
38
39 dataserver(key query, string data)
40 {
41 if(query == request)
42 {
43 request = "";
44
45 if(data == EOF) // Too Far
46 {
47 if( inc == 1 ) // We just went up 1 space. We go up if a line was found.
48 {
49 line++;
50 llWhisper(0, (string)line + " lines in notecard " + name);
51 inc = 10;
52 line = 10;
53 }
54 else if(inc < 0) // Were going down
55 {
56 line += inc; // Keep going down
57 request = llGetNotecardLine(name,line);
58 }
59 else if(inc > 0) // Were going up
60 {
61 inc = - inc / 2; // Go back (down) half as much.
62 line += inc;
63 request = llGetNotecardLine(name,line);
64 }
65 else // Error!
66 {
67 llWhisper(0, "inc == 0!");
68 }
69 }
70 else
71 {
72 if( inc == - 1 ) // We just went down 1 space. We go down if EOF.
73 {
74 line++;
75 if(data == "") llWhisper(0, "Notecard " + name + " is empty");
76 else llWhisper(0, (string)line + " lines in notecard " + name);
77 inc = START_INC;
78 line = START_LINE;
79 }
80 else if(inc > 0) // Were going up
81 {
82 line += inc; // Keep going up.
83 request = llGetNotecardLine(name,line);
84 }
85 else if(inc < 0) // Were going down
86 {
87 inc = - inc / 2; // Go back (up) half as much.
88 line += inc;
89 request = llGetNotecardLine(name,line);
90 }
91 else // Error!
92 {
93 llWhisper(0, "inc == 0!");
94 }
95 }
96 }
97 }
98 }

Back to the Best Free Tools in Second Life and OpenSim.