Difference between revisions of "Config Card Reader"
Jump to navigation
Jump to search
Admindiamond (talk | contribs) (Created page with "OSSL configuration card reader. ==== Licence ==== <syntaxhighlight lang="" line> BSD 3-Clause License Copyright (c) 2020, Sara Payne All rights reserved. Redistribution and...") |
Admindiamond (talk | contribs) m (added config card reader page) |
||
Line 1: | Line 1: | ||
− | OSSL configuration card reader. | + | OSSL configuration card reader written using OSSL. This script will work in Opensim but will not work in Second Life. <br> |
+ | * Change the name of the notecard to be read in the User Changeable Code | ||
+ | * Blank lines are ignored | ||
+ | * Lines with a # at the start are ignored for comments | ||
+ | * Add your processing for each line read in the same place | ||
+ | |||
Line 9: | Line 14: | ||
Redistribution and use in source and binary forms, with or without | Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | modification, are permitted provided that the following conditions are met: | ||
− | 1. Redistributions of source code must retain the above copyright notice, this | + | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
− | |||
2. Redistributions in binary form must reproduce the above copyright notice, | 2. Redistributions in binary form must reproduce the above copyright notice, | ||
− | this list of conditions and the following disclaimer in the documentation | + | this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
− | + | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | |
− | 3. Neither the name of the copyright holder nor the names of its | ||
− | |||
− | |||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
Line 42: | Line 43: | ||
UserName = Manwa Pastorelli | UserName = Manwa Pastorelli | ||
UserName = Sara Payne | UserName = Sara Payne | ||
− | The line is then processed in | + | The line is then processed in whatever way you wish taking the part before the equals sign as the instruction and the part after as the data. |
*/ | */ | ||
Line 53: | Line 54: | ||
ProcessInstructionLine(string instruction, string data) | ProcessInstructionLine(string instruction, string data) | ||
{ | { | ||
− | //add your code here for | + | //add your code here for whatever you wish to do with the line you have just read. |
} | } | ||
//======================== | //======================== |
Revision as of 20:48, 26 July 2020
OSSL configuration card reader written using OSSL. This script will work in Opensim but will not work in Second Life.
- Change the name of the notecard to be read in the User Changeable Code
- Blank lines are ignored
- Lines with a # at the start are ignored for comments
- Add your processing for each line read in the same place
Licence
BSD 3-Clause License
Copyright (c) 2020, Sara Payne
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 /*
2 Config Card Reader
3 ==================
4 Blank Lines are ignored
5 Lines starting with # are also ignored
6 Only lines which contain an "=" sign will be read.
7 White Space Safe: ("InstructionType=DataType" is the same as "InstructionType = DataType", which is the same as " InstructionType = DataType ")
8 Capital Letters are all converted to lower case to make it less prone to user error ("InstructionType=DataType" is the same as "instructiontype=datatype").
9 Example Of A Line Which would be read:
10 Instruction = Data
11 UserName = Manwa Pastorelli
12 UserName = Sara Payne
13 The line is then processed in whatever way you wish taking the part before the equals sign as the instruction and the part after as the data.
14 */
15
16
17
18 //User Changeable Code
19 //======================
20 string configCardName = "My Notecard Name"; //change this to the name of the notecard you wish to read
21
22 ProcessInstructionLine(string instruction, string data)
23 {
24 //add your code here for whatever you wish to do with the line you have just read.
25 }
26 //========================
27 //End User Changeable Code
28
29 string CleanUpString(string inputString)
30 {
31 string cleanString = llStringTrim( llToLower(inputString), STRING_TRIM );
32 return cleanString;
33 }
34
35 ReadConfigCards(string notecardName)
36 { //Reads the named config card if it exists
37 if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
38 { //only come here if the name notecard actually exists, otherwise give the user an error
39 integer notecardLength = osGetNumberOfNotecardLines(notecardName); //gets the length of the notecard
40 integer index; //defines the index for the next line
41 for (index = 0; index < notecardLength; ++index)
42 { //loops through the notecard line by line
43 string currentLine = osGetNotecardLine(notecardName,index); //contents of the current line exactly as it is in the notecard
44 string firstChar = llGetSubString(currentLine, 0,0); //gets the first character of this line
45 integer equalsIndex = llSubStringIndex(currentLine, "="); //gets the position of hte equals sign on this line if it exists
46 if (currentLine != "" && firstChar != "#" && equalsIndex != -1 )
47 { //only come here if the line has content, it does not start with # and it contains an equal sign
48 string instruction = llGetSubString (currentLine, 0, equalsIndex-1); //everything before the equals sign
49 string data = llGetSubString(currentLine, equalsIndex+1, -1); //everything after the equals sign
50 instruction = CleanUpString (instruction); //sends the instruvtion to the cleanup method to remove white space and turn to lower case
51 data = CleanUpString (data); //sends the data to the cleanup method to remove white space and turn to lower case
52 ProcessInstructionLine(instruction, data); //sends the instruction and the data to the Process instruction method
53 }//close if the line is valid
54 else
55 {
56 if ( (currentLine != "") && (firstChar != "#") && (equalsIndex == -1))
57 {
58 llOwnerSay("Line number: " + (string)index + " is malformed. It is not blank, and does not begin with a #, yet it contains no equals sign.");
59 }
60 }
61 }
62 }//close if the notecard exists
63 else
64 { //the named notecard does not exist, send an error to the user.
65 llOwnerSay ("The notecard called " + notecardName + " is missing, please address this");
66 }//close error the notecard does not exist
67 }//close read config card.
68
69 default
70 {
71 state_entry()
72 { //main entry point of the script, this runs when the script starts
73 ReadConfigCards(configCardName); //calls the read config card method passing the name of the card defined in the global variables above
74 }//close state entry
75 }//close default