f89b065b-ea47-b403-c0fe-05fc842df4a7_script.lsl 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Choice (for Sloodle 0.3)
  4. // This script represents an item on the graph 'legend'.
  5. //
  6. // Copyright (c) 2008 Sloodle
  7. // Released under the GNU GPL
  8. //
  9. // Contributors:
  10. // Peter R. Bloomfield
  11. //
  12. integer SLOODLE_CHANNEL_OBJECT_CHOICE = -1639270051;
  13. // Choice commands
  14. // Update the specified option. Followed by "|num|text|colour|count|prop"
  15. // - num is a local option identifier
  16. // - text is the caption to display for this option
  17. // - colour is a colour vector (cast to a string)
  18. // - count is the number selected so far (or -1 if we don't want to display any)
  19. // - prop is the proportion of maximum size to show (between 0 and 1)
  20. string SLOODLE_CHOICE_UPDATE_OPTION = "do:updateoption";
  21. // Select the specified option. Followed by "|num" (num is a local option identifier)
  22. string SLOODLE_CHOICE_SELECT_OPTION = "do:selectoption";
  23. // The local number of this option
  24. integer myoptionnum = -1;
  25. // Process an update command.
  26. // (parts should be a list of parts from the incoming command).
  27. // Returns true if successful, or false otherwise.
  28. integer process_update_command(list parts)
  29. {
  30. // Get our option number
  31. myoptionnum = (integer)llGetObjectDesc();
  32. // We should have several parameters: "command|num|text|colour|count|prop"
  33. if (llGetListLength(parts) < 6) return FALSE;
  34. // Make sure the option number matches this one
  35. if (myoptionnum != (integer)llList2String(parts, 1)) return FALSE;
  36. // Extract the data
  37. string mytext = llList2String(parts, 2);
  38. vector mycol = (vector)llList2String(parts, 3);
  39. integer mycount = (integer)llList2String(parts, 4);
  40. // Set the colour
  41. llSetColor(mycol, ALL_SIDES);
  42. // Set the caption (add the count, if we have one)
  43. if (mycount >= 0) mytext += " [" + (string)mycount + "]";
  44. llSetText(mytext, mycol, 0.9);
  45. return TRUE;
  46. }
  47. // Reset this option back to defaults
  48. reset_option()
  49. {
  50. myoptionnum = -1;
  51. llSetText("", <0.0, 0.0, 0.0>, 0.0);
  52. llSetColor(<1.0,1.0,1.0>, ALL_SIDES);
  53. }
  54. // Uninitialised
  55. default
  56. {
  57. state_entry()
  58. {
  59. reset_option();
  60. }
  61. link_message(integer sender_num, integer num, string sval, key kval)
  62. {
  63. // Check the channel
  64. if (num == SLOODLE_CHANNEL_OBJECT_CHOICE) {
  65. // Parse the string
  66. list parts = llParseString2List(sval, ["|"], []);
  67. string cmd = llList2String(parts, 0);
  68. // Check the command
  69. if (cmd == "do:reset") {
  70. reset_option();
  71. } else if (cmd == SLOODLE_CHOICE_UPDATE_OPTION) {
  72. if (process_update_command(parts)) state ready;
  73. }
  74. }
  75. }
  76. }
  77. // Ready and responding to interactions
  78. state ready
  79. {
  80. link_message(integer sender_num, integer num, string sval, key kval)
  81. {
  82. // Check the channel
  83. if (num == SLOODLE_CHANNEL_OBJECT_CHOICE) {
  84. // Parse the string
  85. list parts = llParseString2List(sval, ["|"], []);
  86. string cmd = llList2String(parts, 0);
  87. // Check the command
  88. if (cmd == "do:reset") {
  89. state default;
  90. } else if (cmd == SLOODLE_CHOICE_UPDATE_OPTION) {
  91. process_update_command(parts);
  92. }
  93. }
  94. }
  95. //touch_start(integer num)
  96. //{
  97. // // Go through each toucher, and notify the choice
  98. // integer i = 0;
  99. // for (i=0; i < num; i++) {
  100. // llMessageLinked(LINK_SET, SLOODLE_CHANNEL_OBJECT_CHOICE, SLOODLE_CHOICE_SELECT_OPTION + "|" + (string)myoptionnum, llDetectedKey(i));
  101. // }
  102. //}
  103. }
  104. // Please leave the following line intact to show where the script lives in Git:
  105. // SLOODLE LSL Script Git Location: mod/choice-1.0/objects/default/assets/sloodle_choice_option_legend.lslp