Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This file contains a series of defines and functions that will
- allow you to use linkSetData memory for lists. These lists will
- not have all the versitlity of normal LSL lists.
- The format in LinksetData memory are as follows.
- The first entry in a list is the master header file. It is
- defined as the following.
- linkset listName is the list listName and the data is the number of
- entries the list.
- <listName> -> <list entries number>
- the format of each list entry is as follows
- <listName>|<entrynumber>:<data>
- */
- #include "color.lsl"
- #define DEBUG
- DS(string sayd)
- {
- #ifdef DEBUG
- llOwnerSay(sayd);
- #endif
- }
- // The first step is the define the linkSetList entry
- integer linkSetDefine(string listName)
- {
- // test to see if entry already exists, if so return error
- // of -1
- if(llLinksetDataRead(listName) != "")
- return -1;
- else
- llLinksetDataWrite(listName, "0");
- return 1; // linkSetList Created.
- }
- // add a entry to the linkset entry and increment the
- // the count by one when adding. create the linkSet
- // if it does not exist. any data other than a string
- // must be typecast to a string.
- integer addLinkData(string listName, string data)
- {
- integer tcList;
- // if listName exists, add link
- // and increment count.
- if(linkSetDefine(listName) == 1)
- tcList = incrmLinkCount(listName, 0);
- else
- tcList = incrmLinkCount(listName, 1);
- llLinksetDataWrite(listName +"|"+ (string) tcList +":"+data, "0");
- return tcList;
- }
- // get count total from base and increase it by 'count'
- integer incrmLinkCount(string listName, integer count)
- {
- integer currentNum = (integer) llLinksetDataRead(listName);
- currentNum += count;
- llLinksetDataWrite(listName, (string) currentNum);
- return currentNum;
- }
- // Return the number of entries in a linkSetList
- integer GetLinkSetListLength(string listName)
- {
- // return error if linkSetList does not exits of -1
- integer listLength = (integer) llLinksetDataRead(listName);
- if(listLength == 0)
- return -1;
- else
- return (listLength + 1);
- }
- // returns a string that is at index in src
- string linkList2String(string src, integer index)
- {
- string found;
- string searchFor = src+"|"+(string) index +":";
- found = (string) llLinksetDataFindKeys("^" + searchFor, 0, 1);
- return llList2String(llParseString2List(found, [":"], []), 1);
- }
- default
- {
- state_entry()
- {
- DS("f " + linkList2String("goat", 1));
- // integer i;
- // for(i = 0; i < GetLinkSetListLength("goat"); ++i)
- // DS((string) i +":"+linkList2String("goat", i));
- // DS("----");
- // for(i = 0; i < llLinksetDataCountKeys(); ++i)
- // DS((string) llLinksetDataListKeys(i, 1));
- }
- touch_start(integer num_detected)
- {
- llResetTime();
- }
- touch_end(integer num_detected)
- {
- if(llGetTime() > 2)
- llLinksetDataReset();
- else
- {
- //DS((string) addLinkData("test", (string) llGenerateKey()));
- DS((string) addLinkData("goat", (string) llGenerateKey()));
- DS(llDumpList2String(llLinksetDataListKeys(0,0), "\n"));
- }
- }
- linkset_data(integer action, string name, string value)
- {
- llSetText((string) llLinksetDataAvailable()
- + "\n"+(string) llLinksetDataCountKeys(), GREEN, TRUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement