2 // add-in... huffware script: notecard library, by fred huffhines
4 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
5 // do not use it in objects without fully realizing you are implicitly accepting that license.
8 // items controlled by the notecard...
10 string NOTECARD_SIGNATURE = "#hoopy"; // the first line of the notecard must be this.
12 string current_notecard_name = ""; // the name of the card we're reading now.
13 key current_query_id = NULL_KEY; // the query ID for the current notecard.
14 list query_contents; // the lines we have read from the notecard.
15 integer line_number; // which line are we at in notecard?
16 integer debug = FALSE;
18 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
19 // this pattern is an uncommon thing to see in text, so we use it to separate
20 // our commands in link messages.
24 // we keep the same notecard name, in case it's still good. we want to
25 // avoid re-reading the notecard unless we see an inventory change.
26 current_query_id = NULL_KEY;
31 // returns a non-empty string if "to_check" defines contents for "variable_name".
32 string defines_variable(string to_check, string variable_name)
34 // clean initial spaces.
35 while (llGetSubString(to_check, 0, 0) == " ")
36 to_check = llDeleteSubString(to_check, 0, 0);
37 if (!is_prefix(to_check, variable_name)) return "";
38 to_check = llDeleteSubString(to_check, 0, llStringLength(variable_name) - 1);
39 // clean any spaces or valid assignment characters.
40 while ( (llGetSubString(to_check, 0, 0) == " ")
41 || (llGetSubString(to_check, 0, 0) == "=")
42 || (llGetSubString(to_check, 0, 0) == ",") )
43 to_check = llDeleteSubString(to_check, 0, 0);
45 log_it("set " + variable_name + " = " + to_check);
46 // return what's left of the string.
50 parse_variable_definition(string to_parse)
52 string content; // filled after finding a variable name.
53 string texture_name; // temporary used in reading texture name.
56 // if ( (content = defines_variable(to_parse, "debug")) != "")
57 // debug = (integer)content;
61 process_particle_settings(list particle_definitions)
63 integer current_item = 0;
64 integer max_items = llGetListLength(particle_definitions);
65 while (current_item < max_items) {
66 string curr_line = llList2String(particle_definitions, current_item);
67 parse_variable_definition(curr_line);
74 if (current_notecard_name != "") return;
75 current_notecard_name = llGetInventoryName(INVENTORY_NOTECARD, 0);
76 // if the notecard is real, then we will start reading it.
77 if (current_notecard_name != "") {
80 current_query_id = llGetNotecardLine(current_notecard_name, 0);
89 integer debug_num = 0;
91 // a debugging output method. can be disabled entirely in one place.
95 // tell this to the owner.
96 llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
97 // say this on open chat, but use an unusual channel.
98 // llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
103 // joins a list of parameters using the parameter sentinel for the library.
104 string wrap_parameters(list to_flatten)
105 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
107 // handles when blank strings need to come through the pipe.
108 string wrap_blank_string(string to_wrap)
110 if (llStringLength(to_wrap)) return to_wrap; // that one is okay.
111 return "\"\""; // return a quoted nothing as a signal for a blank.
114 // undoes a previously wrapped blank string.
115 string interpret_blank_string(string to_unwrap)
117 if (to_unwrap == "\"\"") return ""; // that was an encoded blank.
118 return to_unwrap; // no encoding.
123 // returns a number at most maximum and at least minimum.
124 // if "allow_negative" is TRUE, then the return may be positive or negative.
125 float randomize_within_range(float minimum, float maximum, integer allow_negative)
127 float to_return = minimum + llFrand(maximum - minimum);
128 if (allow_negative) {
129 if (llFrand(1.0) < 0.5) to_return *= -1.0;
134 // the string processing methods are not case sensitive.
136 // returns TRUE if the "pattern" is found in the "full_string".
137 integer matches_substring(string full_string, string pattern)
138 { return (find_substring(full_string, pattern) >= 0); }
140 // returns the index of the first occurrence of "pattern" inside
141 // the "full_string". if it is not found, then a negative number is returned.
142 integer find_substring(string full_string, string pattern)
143 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
145 // returns TRUE if the "prefix" string is the first part of "compare_with".
146 integer is_prefix(string compare_with, string prefix)
147 { return find_substring(compare_with, prefix) == 0; }
152 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
153 on_rez(integer parm) { state rerun; }
155 state rerun { state_entry() { state default; } }
163 check_for_notecard();
166 changed(integer change_type) {
167 if (change_type != CHANGED_INVENTORY) {
168 // we only care about inventory changes here.
171 if (current_query_id != NULL_KEY) {
172 // we're already reading a card right now.
175 // make sure we reset the old name.
176 current_notecard_name = "";
177 check_for_notecard();
180 dataserver(key query_id, string data) {
181 if (query_id != current_query_id) {
182 log_it("not our query id somehow?");
183 //log_it("weird query had: " + (string)data);
186 // if we're not at the end of the notecard we're reading...
189 if (data != NOTECARD_SIGNATURE) {
190 // this card has the wrong signature at the top. quit bothering
194 log_it("starting to read notecard " + current_notecard_name + "...");
197 // add the non-blank line to our destination list.
198 query_contents += data;
199 //log_it("line " + (string)line_number + ": data=" + data);
201 line_number++; // increase the line count.
202 // request the next line from the notecard.
203 current_query_id = llGetNotecardLine(current_notecard_name, line_number);
205 // no more data, so we're done with this card.
206 current_query_id = NULL_KEY;
207 if (!llGetListLength(query_contents)) {
208 // nothing was read? the heck with this card.
209 current_notecard_name = ""; // toss bad card.
212 log_it("notecard said:\n" + (string)(query_contents));
213 log_it("done reading notecard " + current_notecard_name + ".");