Difference between revisions of "LlReadKeyValue"

From Second Life Wiki
Jump to navigation Jump to search
m (will fix this later with a subtype.)
m (Updated result parsing in the example)
Line 26: Line 26:
         trans = llReadKeyValue("FOO");
         trans = llReadKeyValue("FOO");
     }
     }
}
    dataserver(key t, string value)
 
dataserver(key t, string value)
{
    if (t == trans)
     {
     {
        // our llReadKeyValue transaction is done
         if (t == trans)
        list result = llCSV2List(value);
         if (llList2Integer(result, 0) == 1)
         {
         {
             // the key-value pair was successfully read
             // our llReadKeyValue transaction is done
            llSay(0, "New key-value pair value: " + llList2String(1));
            if (llGetSubString(value, 0, 0) == "1")
        }
            {
        else
                // the key-value pair was successfully read
        {
                llSay(0, "New key-value pair value: " + llGetSubString(value, 2, -1));
            // the key-value pair was not created
            }
            llSay(0, "Key-value pair doesn't exist");
            else
         }
            {
     }  
                // the key-value pair failed to read
                integer error =  (integer)llGetSubString(value, 2, -1);
                llSay(0, "Key-value failed to read: " + llGetExperienceErrorMessage(error));
            }
         }  
     }
}</lsl>}}
}</lsl>}}

Revision as of 10:17, 9 July 2014

Summary

Function: key llReadKeyValue( string k );

Start an asynchronous transaction to read the value associated with the specified key and the specified experience.
Returns the key id of the transaction.

• string k The key for the key-value pair

The dataserver callback parameters are:

  • A key containing the transaction ID returned from llReadKeyValue
  • A string containing a comma-delimited list. The first item is a boolean specifying if the transaction succeeded (1) or not (0). The second item is a string with a status/error message if it failed or the value if the transaction succeeded.

Examples

<lsl>key trans; default {

   state_entry()
   {
       trans = llReadKeyValue("FOO");
   }
   dataserver(key t, string value)
   {
       if (t == trans)
       {
           // our llReadKeyValue transaction is done
           if (llGetSubString(value, 0, 0) == "1")
           {
               // the key-value pair was successfully read
               llSay(0, "New key-value pair value: " + llGetSubString(value, 2, -1));
           }
           else
           {
               // the key-value pair failed to read
               integer error =  (integer)llGetSubString(value, 2, -1);
               llSay(0, "Key-value failed to read: " + llGetExperienceErrorMessage(error));
           }
       } 
   }
}</lsl>

Deep Notes

Signature

function key llReadKeyValue( string k );