memory_controller.lslp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /**********************************************************************************************
  4. * memory_controller.lsl
  5. * Copyright (c) 2009 Paul Preibisch
  6. * Released under the GNU GPL 3.0
  7. * This script can be used in your scripts, but you must include this copyright header as per the GPL Licence
  8. * For more information about GPL 3.0 - see: http://www.gnu.org/copyleft/gpl.html
  9. * Part of the SLOODLE Project see http://sloodle.org
  10. *
  11. * Contributors:
  12. * Paul G. Preibisch (Fire Centaur in SL)
  13. * fire@b3dMultiTech.com
  14. *
  15. * INTENT
  16. * This script was created so that we can add a gaming element to the SLOODLE Educational Project
  17. * See http://sloodle.org
  18. *
  19. * This script is an example of how to issue commands to store data in mem_array scripts. See the documentation
  20. * in the mem_array scripts for more information
  21. *
  22. * I hope this script is useful to you, and encourages you to make some exciting new scripts and help us all
  23. * expand the virtual world - and maybe even make a few educational games!
  24. *
  25. * Sincerely, Paul Preibisch
  26. */
  27. integer DATA0; //constant to make code more readible. Used in llList2String commands to retrieve a data field in data0
  28. integer DATA1; //constant to make code more readible. Used in llList2String commands to retrieve a data field in column1
  29. integer MEMORY_CONTROLLER=-1; //all messages to the MEMORY CONTROLLER should be sent on -1 FOR link_num in linked messages
  30. string command; //local var used to determin which command was sent
  31. integer i; //local var used in for loops
  32. string data0; //temporary var, represents a single data field value in column0
  33. string data1; //temporary var, represents a single data field value in column1
  34. string response; //local var to determine response received from mem_arrays
  35. string data; //local var used in linked messages
  36. list commandList; //local var used in linked messages
  37. /***********************************************
  38. * clean()
  39. * Is used so that sending of linked messages is more readable by humans. Ie: instead of sending a linked message as
  40. * PLAYSOUND|50091bcd-d86d-3749-c8a2-055842b33484|soundPlayer 3|0.8 we send it instead like this:
  41. * COMMAND:PLAYSOUND|SOUND_UUID:50091bcd-d86d-3749-c8a2-055842b33484|SCRIPT_NAME:soundPlayer 3|VOLUME:0.8
  42. * By adding a context to the messages, the programmer can understand whats going on when debugging
  43. * All this function does is strip off the text before the ":" char
  44. ***********************************************/
  45. string clean(string cmd){
  46. return llList2String(llParseString2List(cmd, [":"],[]),1);
  47. }
  48. default {
  49. state_entry() {
  50. llListen(0, "",llGetOwner(),"");
  51. }
  52. listen(integer channel, string name, key id, string message) {
  53. llOwnerSay("Command Received");
  54. commandList = llParseString2List(message,[" "],[]);
  55. string command = llList2String(commandList, 0);
  56. data0=llList2String(commandList,1);
  57. data1=llList2String(commandList,2);
  58. data="data0:"+data0+"|data1:"+data1;
  59. if (command=="i"){//insert
  60. llOwnerSay("Sending insert command: "+data);
  61. llMessageLinked(LINK_SET,0,"COMMAND:INSERT|"+data, NULL_KEY);
  62. }
  63. else if (command=="r"){//remove
  64. llMessageLinked(LINK_SET,0,"COMMAND:REMOVE|data0:"+data0, NULL_KEY);
  65. llOwnerSay("Sending remove command: "+data);
  66. }
  67. else if (command=="l"){//list
  68. llMessageLinked(LINK_SET,0,"COMMAND:LIST", NULL_KEY);
  69. llOwnerSay("Sending list command: "+data);
  70. }
  71. else if (command=="s"){//search
  72. llMessageLinked(LINK_SET,0,"COMMAND:GETDATA|data0:"+data0, NULL_KEY);
  73. llOwnerSay("Sending search command: "+data);
  74. }
  75. else if (command=="test"){//test
  76. llOwnerSay("Sending test command: "+data);
  77. for (i=0;i<1000;i++){
  78. llMessageLinked(LINK_SET,0,"COMMAND:INSERT|data0:"+(string)llFrand(1000)+"|data1:"+(string)llFrand(1000), NULL_KEY);
  79. }
  80. }
  81. else if (command=="c"){//count
  82. llOwnerSay("Sending count command: "+data);
  83. llMessageLinked(LINK_SET,0,"COMMAND:COUNT|data0:0", NULL_KEY);
  84. }
  85. }
  86. /***********************************************
  87. * link_message
  88. *
  89. * SOURCES:
  90. * Messages come from mem_array
  91. *
  92. * MESSAGES:
  93. * RESPONSE:FOUND SEARCHITEM0|data0:some data|data1:somedata //this is a response from COMMAND:GETDATA|data0:somedata
  94. * RESPONSE:NOTFOUND|data0:"+searchItem0 //this is a response from COMMAND:GETDATA|data0:somedata
  95. * RESPONSE:INSERT COMPLETE|data0:somedata|data1:somedata //this is a response from COMMAND:INSERT|data0:somedata|data1:somedata
  96. * RESPONSE:REMOVED ROW|data0:somedata|data1:somedata //this is a response from COMMAND:REMOVE|data0:somedata
  97. * RESPONSE:NOT FOUND, REMOVE CANCELED|data0:somedata //this is a response from COMMAND:REMOVE|data0:somedata
  98. * RESPONSE:COUNT|number of rows stored //this is a response from COMMAND:COUNT|0 sent to retrieve number of rows
  99. ***********************************************/
  100. link_message(integer sender_num, integer mem_array_channel, string str, key id) {
  101. if (mem_array_channel==MEMORY_CONTROLLER){
  102. commandList = llParseString2List(str,["|"],[]);
  103. response = clean(llList2String(commandList,0));
  104. data0 = clean(llList2String(commandList,1));
  105. data1 = clean(llList2String(commandList,2));
  106. if (response=="FOUND SEARCHITEM0"){
  107. llSay(0,"Found: " + data0+", "+data1);
  108. }else if (response=="NOTFOUND"){
  109. llSay(0,"Not found: " + data0);
  110. }else if (response=="INSERT COMPLETE"){
  111. // llSay(0,"Insert complete: " + data0+", "+data1);
  112. }else if (response=="REMOVED ROW"){
  113. llSay(0,"Removed Row: " + data0+", "+data1);
  114. }else if (response=="NOT FOUND, REMOVE CANCELED"){
  115. llSay(0,"Error - remove canceled. Row not found: " + data0);
  116. }else if (response=="COUNT"){
  117. llSay(0,"Number of rows: " + data0);
  118. }
  119. llRemoteLoadScriptPin(llGetKey(), "mem_array",5577, TRUE, 0);
  120. }
  121. }
  122. }
  123. // Please leave the following line intact to show where the script lives in Git:
  124. // SLOODLE LSL Script Git Location: assets/misc/memory_controller.lslp