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 Configuration_Notecard_Reader  

Configuration_Notecard_Reader

* Create a script
* Read each line of a note card
* Skip over comments
* Skip blank lines
* Notify the owner of the lines with unknown settings
o Unknown setting name
o Missing delimiter (equal sign)
* Notify the owner of missing configuration note card
* Detect when the notecard has been changed
* Offer case-insensitive settings
* Trim white-space from name/value settings
* Initialize with default values
* Detect that the name of the configuration file is a notecard
* Detect that you have reached the end of the file

Category: Notecard Reader
By : Dedric Mauriac
Created: 2011-01-22 Edited: 2011-01-22
Worlds: Second Life

the Zip file

Download all files for Configuration_Notecard_Reader
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Configuration_Notecard_Reader_1.lsl
Get file # 2. Configuration_Notecard_Reader_2.lsl
1 # this is a file to configure your application
2 # blank lines are ignored as well as lines
3 # proceeded with a "#" sign.
4 Name = Dedric Mauriac
5 Favorite Color = Blue

Configuration_Notecard_Reader

The script.

Category: Notecard Reader
By : Dedric Mauriac
Created: 2011-01-22 Edited: 2011-01-22
Worlds: Second Life

1 integer line;
2 string configurationFile = "Application.Config";
3 key readLineId;
4 string AvatarName;
5 string FavoriteColor;
6
7 init()
8 {
9 // reset configuration values to default
10 AvatarName = "Unknown";
11 FavoriteColor = "None";
12
13 // make sure the file exists and is a notecard
14 if(llGetInventoryType(configurationFile) != INVENTORY_NOTECARD)
15 {
16 // notify owner of missing file
17 llOwnerSay("Missing inventory notecard: " + configurationFile);
18 return; // don't do anything else
19 }
20
21 // initialize to start reading from first line
22 line = 0;
23
24 // read the first line
25 readLineId = llGetNotecardLine(configurationFile, line++);
26
27 }
28 processConfiguration(string data)
29 {
30 // if we are at the end of the file
31 if(data == EOF)
32 {
33 // notify the owner
34 llOwnerSay("We are done reading the configuration");
35
36 // notify what was read
37 llOwnerSay("The avatar name is: " + AvatarName);
38 llOwnerSay("The favorite color is: " + FavoriteColor);
39
40 // do not do anything else
41 return;
42 }
43
44 // if we are not working with a blank line
45 if(data != "")
46 {
47 // if the line does not begin with a comment
48 if(llSubStringIndex(data, "#") != 0)
49 {
50 // find first equal sign
51 integer i = llSubStringIndex(data, "=");
52
53 // if line contains equal sign
54 if(i != -1)
55 {
56 // get name of name/value pair
57 string name = llGetSubString(data, 0, i - 1);
58
59 // get value of name/value pair
60 string value = llGetSubString(data, i + 1, -1);
61
62 // trim name
63 list temp = llParseString2List(name, [" "], []);
64 name = llDumpList2String(temp, " ");
65
66 // make name lowercase (case insensitive)
67 name = llToLower(name);
68
69 // trim value
70 temp = llParseString2List(value, [" "], []);
71 value = llDumpList2String(temp, " ");
72
73 // name
74 if(name == "name")
75 AvatarName = value;
76
77 // color
78 else if(name == "favorite color")
79 FavoriteColor = value;
80
81 // unknown name
82 else
83 llOwnerSay("Unknown configuration value: " + name + " on line " + (string)line);
84
85 }
86 else // line does not contain equal sign
87 {
88 llOwnerSay("Configuration could not be read on line " + (string)line);
89 }
90 }
91 }
92
93 // read the next line
94 readLineId = llGetNotecardLine(configurationFile, line++);
95
96 }
97 default
98 {
100 {
101 init();
102 }
103 on_rez(integer start_param)
104 {
105 init();
106 }
107 changed(integer change)
108 {
109 if(change & CHANGED_INVENTORY) init();
110 else if(change & CHANGED_OWNER) init();
111 }
112 dataserver(key request_id, string data)
113 {
114 if(request_id == readLineId)
115 processConfiguration(data);
116
117 }
118 }

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