2 // huffware script: mediatron control, by fred huffhines.
4 // controls the mediatron device and manages menus for the user.
5 // when buttons are clicked, this is the script that arranges for things to
6 // happen. this script also processes the spoken commands from the user.
8 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
9 // do not use it in objects without fully realizing you are implicitly accepting that license.
12 // configurable constants...
14 integer MEDIATRON_CHANNEL = 1008;
15 // fairly arbitrary channel for listening.
17 integer ONLY_OWNER = FALSE;
18 // only listen to the owner's chats?
20 vector TEXT_COLOR = <0.5, 0.7, 0.92>;
21 // the color that the current chapter is displayed in.
23 string LATEX_DRIVER_URL = "http://universalbuilds.com/tib/gif.php?l=";
24 // the URL for turning tex code into tibetan and english bitmaps.
26 // global constants that really should stay constant...
29 // link ids for flinging messages at them.
30 //----these are useless until the OAR link number bug is fixed.
31 //integer ROOT_PRIM_LINK = 1; // by SL conventions.
32 //integer MAIN_VIEWSCREEN_LINK = 2; // the next prim after the root is our viewer.
33 //integer NEXT_BUTTON_LINK = 3;
34 //integer PREVIOUS_BUTTON_LINK = 4;
35 //integer UHHH_BUTTON_LINK = 5;
36 //integer MENU_BUTTON_LINK = 6;
37 //integer BACKGROUND_PLATE_LINK = 7; // the blank whitish plank underneath the main viewscreen.
40 integer DEFAULT_CHANNEL = 1008; // this must remain unchanged so we can dynamically modify help.
42 // commands that can begin the line of text spoken on our special channel.
43 // these are also used for interchange with sub-prims, such as when a button is pushed.
44 string TIBETAN_CHUNK = "tib";
45 string ENGLISH_CHUNK = "en";
46 string NEW_LINE_CMD = "line";
47 string SHOW_BUFFER_CMD = "go";
49 string NEXT_PAGE_CMD = "next";
50 string PREVIOUS_PAGE_CMD = "prev";
52 string RESET_MEDIATRON_CMD = "Reset";
53 string CLEAR_MEDIATRON_CMD = "Clear";
55 string OPEN_MENU_CMD = "menu";
56 string CHAPTER_PICKER_CMD = "chapter";
58 string CHANNEL_CHANGE_CMD = "channel";
59 string DRIVER_WEB_SITE_CMD = "urldriver";
60 string LOAD_WEB_PAGE_CMD = "loadweb";
62 string TEXT_COLOR_CHANGE_CMD = "textcolor";
64 string HELP_CMD = "Help";
66 // config / control menus that we support.
67 string STATUS_ITEM = "Status";
68 string AUTHORIZE_ITEM = "Authorize";
69 string TEXT_COLOR_ITEM = "Text Color";
70 string CHANNEL_ITEM = "Channel";
71 string WEB_SITE_ITEM = "Driver URL";
73 // API for the viewscreen blitter library...
75 integer VIEWSCREEN_BLITTER_HUFFWARE_ID = 10027;
76 // unique ID for the viewscreen services.
77 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
78 // this pattern is an uncommon thing to see in text, so we use it to separate
79 // our commands in link messages.
80 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
81 // used to separate lists of items from each other when stored inside a parameter.
82 // this allows lists to be passed as single string parameters if needed.
83 integer REPLY_DISTANCE = 100008; // offset added to service's huffware id in reply IDs.
85 string SHOW_URL_COMMAND = "#shurl";
86 // requests the viewscreen to show a particular URL as its texture.
87 string RESET_VIEWSCREEN_COMMAND = "#shrz";
88 // resets the viewscreen script to the default state.
89 string SHOW_TEXTURE_COMMAND = "#shtex";
90 // displays a texture on the prim. the first parameter is the texture key or name.
93 // API for moving between the active notecards.
95 // do not redefine these constants.
96 integer SLATE_READER_HUFFWARE_ID = 10028;
97 // the unique id within the huffware system for the noteworthy script to
98 // accept commands on. this is used in llMessageLinked as the num parameter.
100 string RESET_SLATE_READER_COMMAND = "#rsslt";
101 // causes the notecard information to be forgotten and the script restarted.
102 string SR_GET_INFORMATION_COMMAND = "#infy";
103 // used by clients to ask for information about the current number of notecards
104 // available, and their names. this information is sent back on the huffware ID
105 // plus the reply distance. first parm is the number, and the rest are the names.
106 string SR_PLAY_CARD_COMMAND = "#playvo";
107 // picks a particular notecard for reading and send the notecard's contents in a
108 // series of link messages, using this command and the reply distance. there are
109 // two parameters: an integer for the notecard number to read (from 0 through the
110 // number of notecards - 1) and the link number to send the messages to.
113 // the button pushing API.
115 integer BUTTON_PUSHER_HUFFWARE_ID = 10029;
116 // a unique ID within the huffware system for this script.
118 string BUTTON_PUSHED_ALERT = "#btnp";
119 // this event is generated when the button is pushed. the number parameter will be
120 // the huffware id plus the reply distance. the id parameter in the link message will
121 // contain the name of the button that was pushed.
124 // menutini link message API...
126 // do not redefine these constants.
127 integer MENUTINI_HUFFWARE_ID = 10009;
128 // the unique id within the huffware system for the jaunt script to
129 // accept commands on. this is used in llMessageLinked as the num parameter.
130 string SHOW_MENU_COMMAND = "#menu#";
131 // the command that tells menutini to show a menu defined by parameters
132 // that are passed along. these must be: the menu name, the menu's title
133 // (which is really the info to show as content in the main box of the menu),
134 // the wrapped list of commands to show as menu buttons, the menu system
135 // channel's for listening, and the key to listen to.
136 // the reply will include: the menu name, the choice made and the key for
140 // global variables...
142 string buffer_text; // the buffer being accumulated for display.
144 integer page_number; // current page shown: ranges from zero to number of notecards - 1.
146 integer maximum_notecards; // the maximum notecards that can be shown.
148 list notecard_choices; // the chapters that can be chosen.
150 integer listening_handle; // tracks our listening so we can change channels.
152 set_viewscreen_texture()
154 // get the video texture they want to use for the parcel.
155 key texture_key = llList2Key(llParcelMediaQuery([PARCEL_MEDIA_COMMAND_TEXTURE]), 0);
156 if (texture_key == NULL_KEY) {
157 // there wasn't one set yet. we can't do much about that here. we'll use the
158 // last inventory texture instead, which usually will be our proper image.
159 texture_key = llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE,
160 llGetInventoryNumber(INVENTORY_TEXTURE) - 1));
161 if (texture_key == NULL_KEY) return; // now we're hosed; there's no texture.
163 // set the main viewer prim to the chosen texture...
164 llMessageLinked(LINK_SET, VIEWSCREEN_BLITTER_HUFFWARE_ID,
165 SHOW_TEXTURE_COMMAND, (string)texture_key);
168 // checks the parcel's media texture to make sure it's set. if it's not, we reset it to
169 // our favorite version.
170 fix_parcel_media_texture()
172 // get the video texture they want to use for the parcel.
173 key texture_key = llList2Key(llParcelMediaQuery([PARCEL_MEDIA_COMMAND_TEXTURE]), 0);
174 if (texture_key == NULL_KEY) {
175 // there wasn't one set yet, so we need to fix that. we'll use the last inventory
176 // texture, which usually will be our proper image. this is a distinct chore from
177 // setting the viewscreen's texture, since we don't know that we have the capability
178 // to change the parcel media texture yet.
179 texture_key = llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTURE,
180 llGetInventoryNumber(INVENTORY_TEXTURE) - 1));
181 if (texture_key != NULL_KEY) {
182 llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_TEXTURE, texture_key]);
183 if (llGetLandOwnerAt(llGetPos()) != llGetOwner()) {
184 log_it("There is a problem with the parcel media: "
185 + llGetObjectName() + " is not owned by the parcel owner.");
187 log_it("No media texture found for video on this parcel. Using default texture: "
188 + (string)texture_key);
191 log_it("The object does not seem to contain any textures; we need at "
192 + "least one for a default viewscreen image.");
197 // asks the slate reader to find out what cards there are for us.
200 // now we find out what's really present so we can offer a menu.
201 llMessageLinked(LINK_THIS, SLATE_READER_HUFFWARE_ID,
202 SR_GET_INFORMATION_COMMAND, "");
205 // fixes the viewscreen face and parcel media texture, if needed, and gets the mediatron
206 // ready for commands.
207 initialize_mediatron()
209 fix_parcel_media_texture();
210 set_viewscreen_texture();
211 llSetText("", TEXT_COLOR, 0.0);
215 // listening for commands from the user.
216 listening_handle = llListen(MEDIATRON_CHANNEL, "", NULL_KEY, "");
218 llSay(0, "Now listening for commands on channel /" + (string)MEDIATRON_CHANNEL);
221 // locates the space boundaries between words and returns just a list of the words,
222 // with no spaces remaining.
223 list break_on_spaces(string msg)
225 if (!llStringLength(msg)) return []; // no length means no list.
228 for (indy = 0; indy < llStringLength(msg); indy++) {
229 integer space_posn = llSubStringIndex(msg, " ");
230 if (space_posn < 0) {
231 // no spaces left, so use the whole string.
232 to_return += [ msg ];
233 indy = 2 * llStringLength(msg);
235 // we found a space. chop out the first part to add to the list and
236 // keep the second part for further scanning.
237 to_return += [ llGetSubString(msg, 0, space_posn - 1) ];
238 // we also trash any additional spaces that were after the one we found.
239 msg = llStringTrim(llGetSubString(msg, space_posn + 1, -1), STRING_TRIM);
240 indy = -1; // start over at top of string.
246 integer random_channel() { return -(integer)(llFrand(40000) + 20000); }
248 simply_display_menu(string menu_name, string title, list buttons)
250 integer menu_channel = random_channel();
251 key listen_to = llGetOwner();
252 llMessageLinked(LINK_THIS, MENUTINI_HUFFWARE_ID, SHOW_MENU_COMMAND,
253 menu_name + HUFFWARE_PARM_SEPARATOR
254 + title + HUFFWARE_PARM_SEPARATOR
255 + wrap_item_list(buttons) + HUFFWARE_PARM_SEPARATOR
256 + (string)menu_channel + HUFFWARE_PARM_SEPARATOR
257 + (string)listen_to);
260 // handles when a button on the device has been clicked.
261 process_button_clicks(string msg, key id)
263 if (msg != BUTTON_PUSHED_ALERT) return; // uhhhh, not sure what that was.
264 if (id == NEXT_PAGE_CMD) {
265 hear_voices(FALSE, "self", llGetOwner(), id);
266 } else if (id == PREVIOUS_PAGE_CMD) {
267 hear_voices(FALSE, "self", llGetOwner(), id);
268 } else if (id == CHAPTER_PICKER_CMD) {
270 string list_as_block;
272 for (indy = 0; indy < llGetListLength(notecard_choices); indy++) {
273 string curr_name = prune_notecard_name(llList2String(notecard_choices, indy));
274 pruned_choices += [ curr_name ];
275 list_as_block += (string)(indy + 1) + ". " + curr_name;
276 if (indy < llGetListLength(notecard_choices) - 1) list_as_block += "\n";
278 simply_display_menu(CHAPTER_PICKER_CMD, "Pick the Chapter to display...\n" + list_as_block,
280 } else if (id == OPEN_MENU_CMD) {
281 simply_display_menu(OPEN_MENU_CMD, "TibSlate Mediatron Control Menu",
282 [ HELP_CMD, STATUS_ITEM, AUTHORIZE_ITEM, TEXT_COLOR_ITEM, CHANNEL_ITEM,
283 WEB_SITE_ITEM, CLEAR_MEDIATRON_CMD, RESET_MEDIATRON_CMD ]);
287 string bool_string_for_int(integer truth)
289 if (truth) return "true"; else return "false";
292 tell_not_authorized()
294 llSay(0, "The operation you have chosen can only be performed by the owner.");
297 // handles the response message when the user chooses a button.
298 react_to_menu(string msg, key id)
300 list parms = llParseString2List(id, [HUFFWARE_PARM_SEPARATOR], []);
301 string menu_name = llList2String(parms, 0);
302 string which_choice = llList2String(parms, 1);
303 key av_key = llList2String(parms, 2);
304 if (ONLY_OWNER && (av_key != llGetOwner())) {
305 tell_not_authorized();
308 //log_it("you clicked " + which_choice + " item for av " + av_key);
310 if (menu_name == CHAPTER_PICKER_CMD) {
311 // find the index of the choice if we can, and make the choice be the new page.
312 page_number = find_similar_in_list(notecard_choices, which_choice);
315 } else if (menu_name == OPEN_MENU_CMD) {
316 // show the main control menu.
317 if (which_choice == STATUS_ITEM) {
318 llSay(0, "Status...\n\tMemory Free " + (string)llGetFreeMemory()
319 + "\n\tListening Channel " + (string)MEDIATRON_CHANNEL
320 + "\n\tOwner Only? " + bool_string_for_int(ONLY_OWNER));
322 } else if (which_choice == AUTHORIZE_ITEM) {
323 if (av_key != llGetOwner()) {
324 // this option isn't allowed for anyone but the owner, ever.
325 tell_not_authorized();
328 simply_display_menu(AUTHORIZE_ITEM, "Authorization required to use device...",
329 [ "Any User", "Only Owner" ]);
331 } else if (which_choice == TEXT_COLOR_ITEM) {
332 llSay(0, "To change the text color, say\n\t/"
333 + (string)MEDIATRON_CHANNEL + " " + TEXT_COLOR_CHANGE_CMD
334 + " <r, g, b>\nwhere r, g, and b are the red, green and blue components of the color.\n"
335 + "Note that r, g & b can range from 0 to 1 inclusive.");
337 } else if (which_choice == CHANNEL_ITEM) {
338 llSay(0, "To change the channel of the viewer, say\n\t/"
339 + (string)MEDIATRON_CHANNEL + " " + CHANNEL_CHANGE_CMD
340 + " N\nwhere N is a number for the new channel.");
342 } else if (which_choice == WEB_SITE_ITEM) {
343 llSay(0, "Current driver web URL: " + LATEX_DRIVER_URL
344 + "\nTo replace this site, say:\n\t/"
345 + (string)MEDIATRON_CHANNEL + " " + DRIVER_WEB_SITE_CMD
346 + " newURL\nNote that this site must be capable of accepting LaTex code and\n"
347 + "converting that into simulator compatible bitmaps.");
350 // handle all the others by just passing this on to the hear voices function.
351 // if it's a known command, we handle it. otherwise we bounce it off the couch.
352 hear_voices(FALSE, "self", llGetOwner(), which_choice);
355 // the remainder of these handle the menu button's menu options...
356 } else if (menu_name == AUTHORIZE_ITEM) {
357 // they chose an option for authorization, so see if it was for only the owner.
358 ONLY_OWNER = is_prefix(which_choice, "only");
359 llSay(0, "now, Owner Only = " + bool_string_for_int(ONLY_OWNER));
363 log_it("i do not understand item " + which_choice + " in "+ menu_name);
366 // processes the responses from the slate reader.
367 handle_slate_items(string msg, key id)
369 if (msg == SR_PLAY_CARD_COMMAND) {
370 // we have gotten some data from our reader.
371 hear_voices(FALSE, "self", llGetOwner(), id);
372 } else if (msg == SR_GET_INFORMATION_COMMAND) {
373 list parms = llParseString2List(id, [HUFFWARE_PARM_SEPARATOR], []);
374 maximum_notecards = llList2Integer(parms, 0);
375 //log_it("got info response, num notes=" + (string)maximum_notecards);
376 notecard_choices = llList2List(parms, 1, -1);
380 // strips off any numerical info to make a more useful notecard name.
381 string prune_notecard_name(string note_name)
383 // we look at the name and remove any numbers in front, so we can avoid cluttering up the
384 // user facing text with the numbers that are used for ordering the notecards.
385 list rip_these = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", " ", "." ];
386 while (llListFindList(rip_these, [ llGetSubString(note_name, 0, 0) ]) >= 0) {
387 // found a number or space or period. rip it off.
388 note_name = llDeleteSubString(note_name, 0, 0);
395 string note_name = prune_notecard_name(llList2String(notecard_choices, page_number));
396 llSetText("Page #" + (string)(page_number + 1)
397 + " -- " + note_name, TEXT_COLOR, 1.0);
400 // shows the contents of the current page's notecard on the viewscreen.
404 llMessageLinked(LINK_THIS, SLATE_READER_HUFFWARE_ID,
405 SR_PLAY_CARD_COMMAND, wrap_parameters([page_number, LINK_THIS]));
408 // tell the viewscreen to display this possible tibetan.
409 // spoken reports whether it's a user speaking or not. if spoken is false, then
410 // the voice is internal from getting notecard info or button clicks.
411 hear_voices(integer spoken, string name, key id, string msg)
413 msg = llStringTrim(msg, STRING_TRIM); // toss extra spaces.
414 if (msg == CLEAR_MEDIATRON_CMD) {
415 // wipe out anything on the screen.
416 set_viewscreen_texture();
417 buffer_text = ""; // toss out any partial buffer also.
418 if (spoken) llSay(0, "Clearing viewscreen.");
419 page_number = -1; // reset page to the spot before the first.
420 llSetText("", TEXT_COLOR, 0.0);
422 } else if ( (msg == RESET_MEDIATRON_CMD) && (id == llGetOwner()) ) {
423 llMessageLinked(LINK_SET, VIEWSCREEN_BLITTER_HUFFWARE_ID,
424 RESET_VIEWSCREEN_COMMAND, "");
425 llMessageLinked(LINK_THIS, SLATE_READER_HUFFWARE_ID,
426 RESET_SLATE_READER_COMMAND, "");
427 if (spoken) llSay(0, "Resetting scripts.");
429 } else if (is_prefix(msg, CHANNEL_CHANGE_CMD)) {
430 integer new_channel = (integer)llGetSubString(msg, llStringLength(CHANNEL_CHANGE_CMD), -1);
431 llSay(0, "New channel is " + (string)new_channel);
432 MEDIATRON_CHANNEL = new_channel;
433 llListenRemove(listening_handle);
434 listening_handle = llListen(MEDIATRON_CHANNEL, "", NULL_KEY, "");
436 } else if (is_prefix(msg, TEXT_COLOR_CHANGE_CMD)) {
437 vector new_col = (vector)llGetSubString(msg, llStringLength(TEXT_COLOR_CHANGE_CMD), -1);
438 llSay(0, "New text color is " + (string)new_col);
439 TEXT_COLOR = new_col;
442 } else if (is_prefix(msg, DRIVER_WEB_SITE_CMD)) {
443 string new_url = llGetSubString(msg, llStringLength(DRIVER_WEB_SITE_CMD), -1);
444 llSay(0, "New driver URL for LaTex: " + (string)new_url);
445 LATEX_DRIVER_URL = new_url;
447 } else if (is_prefix(msg, NEXT_PAGE_CMD)) {
449 if (page_number >= maximum_notecards) {
454 } else if (is_prefix(msg, PREVIOUS_PAGE_CMD)) {
456 if (page_number < 0) {
457 page_number = maximum_notecards - 1;
460 llMessageLinked(LINK_THIS, SLATE_READER_HUFFWARE_ID,
461 SR_PLAY_CARD_COMMAND, wrap_parameters([page_number, LINK_THIS]));
463 } else if (is_prefix(msg, HELP_CMD)) {
466 } else if (is_prefix(msg, LOAD_WEB_PAGE_CMD)) {
467 string new_url = llGetSubString(msg, llStringLength(LOAD_WEB_PAGE_CMD), -1);
468 llSay(0, "Loading web site: " + (string)new_url);
469 llMessageLinked(LINK_SET, VIEWSCREEN_BLITTER_HUFFWARE_ID, SHOW_URL_COMMAND, new_url);
470 buffer_text = ""; // clear the buffer out.
473 // now we try to process the screen buffer commands which we suspect
474 // are in the text that was spoken.
475 list sentence = break_on_spaces(msg);
476 string first_word = llList2String(sentence, 0);
477 //log_it("first word is: " + first_word);
480 for (indo = 1; indo < llGetListLength(sentence); indo++) {
481 if (indo != 1) remainder += " ";
482 remainder += llList2String(sentence, indo);
484 //log_it("remainder is: " + remainder);
486 if (first_word == TIBETAN_CHUNK) {
487 if (spoken) llSay(0, "Added Tibetan: " + remainder);
488 buffer_text += "{\\tib " + remainder + "}{ }";
489 } else if (first_word == ENGLISH_CHUNK) {
490 if (spoken) llSay(0, "Added English: " + remainder);
491 buffer_text += "{" + remainder + " }";
492 } else if (first_word == NEW_LINE_CMD) {
493 if (spoken) llSay(0, "Inserted blank line.");
494 buffer_text += "{\\\\}";
495 } else if (first_word == SHOW_BUFFER_CMD) {
496 if (spoken) llSay(0, "Displaying buffered screen.");
497 // reset text label since that's no longer our page.
498 if (spoken) llSetText("", TEXT_COLOR, 0.0);
499 string url = LATEX_DRIVER_URL + buffer_text;
500 llMessageLinked(LINK_SET, VIEWSCREEN_BLITTER_HUFFWARE_ID, SHOW_URL_COMMAND, url);
501 buffer_text = ""; // clear the buffer out.
503 // treat this as english.
505 if (spoken) llSay(0, "Added English: " + first_word + " " + remainder);
506 buffer_text += "{" + first_word + " " + remainder + "}";
507 // if we're assuming this is english, we will plug in a blank line afterwards.
508 // otherwise a text document will look right awful.
509 buffer_text += "{\\\\}";
513 // hands out any notecards with help in their names.
516 integer count = llGetInventoryNumber(INVENTORY_NOTECARD);
518 list help_cards = [];
519 for (indy = 0; indy < count; indy++) {
520 string note_name = llGetInventoryName(INVENTORY_NOTECARD, indy);
521 if (find_substring(note_name, "help") >= 0)
522 help_cards += [ note_name ];
525 if (llGetListLength(help_cards)) llOwnerSay("Here is the built-in help file...");
526 else llOwnerSay("There are currently no help notecards; sorry.");
527 // iterate on helper cards and give them out.
528 count = llGetListLength(help_cards);
529 for (indy = 0; indy < count; indy++) {
530 string note_name = llList2String(help_cards, indy);
531 llGiveInventory(llGetOwner(), note_name);
539 integer debug_num = 0;
541 // a debugging output method. can be disabled entirely in one place.
542 log_it(string to_say)
545 // tell this to the owner.
546 llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
547 // say this on an unusual channel for chat if it's not intended for general public.
548 // llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
549 // say this on open chat that anyone can hear. we take off the bling for this one.
555 // joins a list of parameters using the parameter sentinel for the library.
556 string wrap_parameters(list to_flatten)
557 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
559 // joins a list of sub-items using the item sentinel for the library.
560 string wrap_item_list(list to_wrap)
561 { return llDumpList2String(to_wrap, HUFFWARE_ITEM_SEPARATOR); }
563 // returns TRUE if the "prefix" string is the first part of "compare_with".
564 integer is_prefix(string compare_with, string prefix)
565 { return (llSubStringIndex(llToLower(compare_with), llToLower(prefix)) == 0); }
567 // returns the index of the first occurrence of "pattern" inside
568 // the "full_string". if it is not found, then a negative number is returned.
569 integer find_substring(string full_string, string pattern)
570 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
572 // locates the string "text" as a partial match in the list to "search_in".
573 integer find_similar_in_list(list search_in, string text)
575 integer len = llGetListLength(search_in);
577 for (i = 0; i < len; i++) {
578 if (find_substring(llList2String(search_in, i), text) >= 0)
585 // huffware script: auto-retire, by fred huffhines, version 2.5.
586 // distributed under BSD-like license.
587 // !! keep in mind that this code must be *copied* into another
588 // !! script that you wish to add auto-retirement capability to.
589 // when a script has auto_retire in it, it can be dropped into an
590 // object and the most recent version of the script will destroy
591 // all older versions.
593 // the version numbers are embedded into the script names themselves.
594 // the notation for versions uses a letter 'v', followed by two numbers
595 // in the form "major.minor".
596 // major and minor versions are implicitly considered as a floating point
597 // number that increases with each newer version of the script. thus,
598 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
599 // and "hazmap v3.2" is a more recent version.
601 // example usage of the auto-retirement script:
604 // auto_retire(); // make sure newest addition is only version of script.
607 // this script is partly based on the self-upgrading scripts from markov brodsky
608 // and jippen faddoul.
611 string self = llGetScriptName(); // the name of this script.
612 list split = compute_basename_and_version(self);
613 if (llGetListLength(split) != 2) return; // nothing to do for this script.
614 string basename = llList2String(split, 0); // script name with no version attached.
615 string version_string = llList2String(split, 1); // the version found.
617 // find any scripts that match the basename. they are variants of this script.
618 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
619 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
620 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
621 // found a basic match at least.
622 list inv_split = compute_basename_and_version(curr_script);
623 if (llGetListLength(inv_split) == 2) {
624 // see if this script is more ancient.
625 string inv_version_string = llList2String(inv_split, 1); // the version found.
626 // must make sure that the retiring script is completely the identical basename;
627 // just matching in the front doesn't make it a relative.
628 if ( (llList2String(inv_split, 0) == basename)
629 && ((float)inv_version_string < (float)version_string) ) {
630 // remove script with same name from inventory that has inferior version.
631 llRemoveInventory(curr_script);
638 // separates the base script name and version number. used by auto_retire.
639 list compute_basename_and_version(string to_chop_up)
641 // minimum script name is 2 characters plus a version.
642 integer space_v_posn;
643 // find the last useful space and 'v' combo.
644 for (space_v_posn = llStringLength(to_chop_up) - 3;
645 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
647 // look for space and v but do nothing else.
649 if (space_v_posn < 2) return []; // no space found.
650 // now we zoom through the stuff after our beloved v character and find any evil
651 // space characters, which are most likely from SL having found a duplicate item
652 // name and not so helpfully renamed it for us.
654 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
655 if (llGetSubString(to_chop_up, indy, indy) == " ") {
656 // found one; zap it. since we're going backwards we don't need to
657 // adjust the loop at all.
658 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
661 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
662 // ditch the space character for our numerical check.
663 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
664 // strip out a 'v' if there is one.
665 if (llGetSubString(chop_suffix, 0, 0) == "v")
666 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
667 // if valid floating point number and greater than zero, that works for our version.
668 string basename = to_chop_up; // script name with no version attached.
669 if ((float)chop_suffix > 0.0) {
670 // this is a big success right here.
671 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
672 return [ basename, chop_suffix ];
674 // seems like we found nothing useful.
685 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
686 on_rez(integer parm) { state rerun; }
688 state rerun { state_entry() { state default; } }
695 initialize_mediatron();
698 listen(integer chan, string name, key id, string msg) {
699 if (chan != MEDIATRON_CHANNEL) return; // how are we even hearing that?
700 if (ONLY_OWNER && (id != llGetOwner())) return; // unauthorized talker.
701 hear_voices(TRUE, name, id, msg);
704 on_rez(integer start_parm) {
708 changed(integer change) {
709 if (change & CHANGED_INVENTORY) {
714 link_message(integer sender, integer num, string msg, key id) {
715 if (num == BUTTON_PUSHER_HUFFWARE_ID + REPLY_DISTANCE) {
716 process_button_clicks(msg, id);
719 if (num == MENUTINI_HUFFWARE_ID + REPLY_DISTANCE) {
720 react_to_menu(msg, id);
723 if (num != SLATE_READER_HUFFWARE_ID + REPLY_DISTANCE) return; // not for us.
724 handle_slate_items(msg, id);