Advertisement
Madi_Perth

Untitled

Nov 14th, 2023
1,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Linden Scripting 3.46 KB | Source Code | 0 0
  1. /*
  2. This file contains a series of defines and functions that will
  3. allow you to use linkSetData memory for lists.  These lists will
  4. not have all the versitlity of normal LSL lists.
  5.  
  6. The format in LinksetData memory are as follows.
  7.  
  8. The first entry in a list is the master header file.  It is
  9. defined as the following.
  10.  
  11. linkset listName is the list listName and the data is the number of
  12. entries the list.
  13.  
  14. <listName> -> <list entries number>
  15.  
  16. the format of each list entry is as follows
  17.  
  18. <listName>|<entrynumber>:<data>
  19.  
  20. */
  21. #include "color.lsl"
  22. #define DEBUG
  23.  
  24. DS(string sayd)
  25. {
  26. #ifdef DEBUG
  27.     llOwnerSay(sayd);
  28. #endif
  29. }
  30.  
  31. // The first step is the define the linkSetList entry
  32. integer linkSetDefine(string listName)
  33. {
  34.     // test to see if entry already exists, if so return error
  35.     // of -1
  36.     if(llLinksetDataRead(listName) != "")
  37.         return -1;
  38.     else
  39.         llLinksetDataWrite(listName, "0");
  40.     return 1; // linkSetList Created.
  41. }
  42.  
  43. // add a entry to the linkset entry and increment the
  44. // the count by one when adding.   create the linkSet
  45. // if it does not exist. any data other than a string
  46. // must be typecast to a string.
  47. integer addLinkData(string listName, string data)
  48. {
  49.     integer tcList;
  50.     // if listName exists, add link
  51.     // and increment count.
  52.     if(linkSetDefine(listName) == 1)
  53.         tcList = incrmLinkCount(listName, 0);
  54.     else
  55.         tcList = incrmLinkCount(listName, 1);
  56.     llLinksetDataWrite(listName +":"+ (string) tcList +":"+data, "0");    
  57.  
  58.     return tcList;
  59. }
  60.  
  61. // get count total from base and increase it by 'count'
  62. integer incrmLinkCount(string listName, integer count)
  63. {
  64.     integer currentNum = (integer) llLinksetDataRead(listName);
  65.    
  66.     currentNum += count;
  67.     llLinksetDataWrite(listName, (string) currentNum);
  68.  
  69.     return currentNum;
  70. }
  71.  
  72. // Return the number of entries in a linkSetList
  73. integer GetLinkSetListLength(string listName)
  74. {
  75.     // return error if linkSetList does not exits of -1
  76.     integer listLength = (integer) llLinksetDataRead(listName);
  77.     if(listLength == 0)
  78.         return -1;
  79.     else
  80.         return (listLength + 1);
  81. }
  82.  
  83. // returns a string that is at index in src
  84. string linkList2String(string src, integer index)
  85. {
  86.     string found;
  87.     string searchFor = src+":"+(string) index +":";
  88.  
  89.     found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
  90.     return llList2String(llParseString2List(found, [":"], []), 2);
  91. }
  92.  
  93. default
  94. {
  95.     state_entry()
  96.     {
  97.  
  98.         DS("f " + linkList2String("goat", 1));
  99.         // integer i;
  100.         // for(i = 0; i < GetLinkSetListLength("goat"); ++i)
  101.         //     DS((string) i +":"+linkList2String("goat", i));
  102.         // DS("----");
  103.         // for(i = 0; i < llLinksetDataCountKeys(); ++i)
  104.         //     DS((string) llLinksetDataListKeys(i, 1));
  105.  
  106.     }
  107.  
  108.     touch_start(integer num_detected)
  109.     {
  110.         llResetTime();
  111.     }
  112.     touch_end(integer num_detected)
  113.     {
  114.         if(llGetTime() > 2)
  115.             llLinksetDataReset();
  116.         else
  117.         {
  118.             //DS((string) addLinkData("test", (string) llGenerateKey()));
  119.             DS((string) addLinkData("goat", (string) llGenerateKey()));
  120.             DS(llDumpList2String(llLinksetDataListKeys(0,0), "\n"));
  121.         }
  122.     }
  123.  
  124.     linkset_data(integer action, string name, string value)
  125.     {
  126.         llSetText((string) llLinksetDataAvailable()
  127.         + "\n"+(string) llLinksetDataCountKeys(), GREEN, TRUE);
  128.     }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement