Advertisement
Madi_Perth

Untitled

Nov 13th, 2023
1,119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Linden Scripting 2.32 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. #define DEBUG
  22.  
  23. DS(string sayd)
  24. {
  25. #ifdef DEBUG
  26.     llOwnerSay(sayd);
  27. #endif
  28. }
  29.  
  30. // The first step is the define the linkSetList entry
  31. integer linkSetDefine(string listName)
  32. {
  33.     // test to see if entry already exists, if so return error
  34.     // of -1
  35.     if(llLinksetDataRead(listName) != "")
  36.         return -1;
  37.     else
  38.         llLinksetDataWrite(listName, "0");
  39.     return 1; // linkSetList Created.
  40. }
  41.  
  42. // add a entry to the linkset entry and increment the
  43. // the count by one when adding.   create the linkSet
  44. // if it does not exist.
  45. integer addLinkData(string listName, string data)
  46. {
  47.     integer tcList;
  48.     // if listName exists, add link
  49.     // and increment count.
  50.     if(linkSetDefine(listName) == 1)
  51.         tcList = incrmLinkCount(listName, 0);
  52.     else
  53.         tcList = incrmLinkCount(listName, 1);
  54.  
  55.     llLinksetDataWrite(listName +"|"+ (string) tcList +"|"+data, "0");    
  56.  
  57.     return tcList;
  58. }
  59.  
  60. // get count total from base and increase it by 'count'
  61. integer incrmLinkCount(string listName, integer count)
  62. {
  63.     integer currentNum = (integer) llLinksetDataRead(listName);
  64.    
  65.     currentNum += count;
  66.     llLinksetDataWrite(listName, (string) currentNum);
  67.  
  68.     return currentNum;
  69. }
  70.  
  71. // Return the number of entries in a linkSetList
  72. integer GetLinkSetListLength(string listName)
  73. {
  74.     // return error if linkSetList does not exits of -1
  75.     string listLength = llLinksetDataRead(listName);
  76.     if(listLength == "")
  77.         return -1;
  78.     else
  79.         return (integer) listLength;
  80. }
  81.  
  82. default
  83. {
  84.     state_entry()
  85.     {
  86.         llLinksetDataReset();
  87.     }
  88.  
  89.     touch_end(integer num_detected)
  90.     {
  91.         DS((string) addLinkData("test", (string) llGenerateKey()));
  92.         DS(llDumpList2String(llLinksetDataListKeys(0,0), "\n"));
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement