Difference between revisions of "LlKeysKeyValue"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[[Category:Experience Tools]]
[[Category:Experience Tools]]
{{LSL_Function
{{LSL_Function
|inject-2={{LSL Function/KeyValue|dl_name=key_names}}
|inject-2={{LSL Function/KeyValue|dl_name=keys
|dl_desc=A list of keys ([[String|strings]]) used in the key-value store
|dl_hover=A list of keys (strings) used in the key-value store}}
{{LSL_Function/Experience|true}}
|func=llKeysKeyValue
|func=llKeysKeyValue
|func_desc=Start an asynchronous transaction to request a number of keys.
|func_desc=Start an asynchronous transaction to request a number of keys from the script's {{LSLGC|Experience}}.
|func_footnote=
|func_footnote=
The [[dataserver]] callback parameters are:
This function will attempt to retrieve the number of keys requested but may return less if there are not enough to fulfill the full amount requested or if the list is too large. The length of the returned list is limited to 4097 characters (the success flag "1" and 4096 characters).  The order keys are returned is not guaranteed but is stable between subsequent calls as long as no keys are added or removed.<br/>
* A key containing the {{LSLGC|Key/handle|handle}} returned from llKeysKeyValue
The error [[XP_ERROR_KEY_NOT_FOUND]] is returned if there index given is greater than or equal to the number of keys.
* A string containing a comma-delimited list.  The first item is a boolean specifying if the transaction succeeded (1) or not (0). On a success result the remaining items are key names. This function will attempt to retrieve the number requested but may return less if there are not enough to fulfill the full amount requested or if the list is too large. The order keys are returned is not guaranteed but is stable between subsequent calls as long as no keys are added or removed. The error [[XP_ERROR_KEY_NOT_FOUND]] is returned if there index given is greater than or equal to the number of keys.
|return_type=key|return_subtype=handle
|return_type=key|return_subtype=handle
|return_text=that can be used to identify the corresponding [[dataserver]] event to determine if this command succeeded or failed.
|return_text=that can be used to identify the corresponding [[dataserver]] event to determine if this command succeeded or failed.
Line 21: Line 23:
*[[llKeyCountKeyValue]]
*[[llKeyCountKeyValue]]
*[[llKeysKeyValue]]
*[[llKeysKeyValue]]
|examples=<lsl>key trans;
|examples=<source lang="lsl2">key trans;
default
default
{
{
Line 29: Line 31:
         trans = llKeysKeyValue(0, 10);
         trans = llKeysKeyValue(0, 10);
     }
     }
}


dataserver(key t, string value)
    dataserver(key t, string value)
{
    if (t == trans)
     {
     {
        // our llKeyCountKeyValue transaction is done
         if (t == trans)
        list result = llCSV2List(value);
         if (llList2Integer(result, 0) == 1)
         {
         {
             llSay(0, "Keys retrieved: "+llGetSubString(value, -1);
             // our llKeysKeyValue transaction is done
        }
            list result = llCSV2List(value);
        else if (llList2String(result, 1) == "key doesn't exist")
            if (llList2Integer(result, 0) == 1)
        {
            {
            // no more keys
                llSay(0, "Keys retrieved: "+(string)llGetSubString(value, 2, -1));
            llSay(0, "No more keys" );
            }
        }
            else if (llList2Integer(result, 1) == XP_ERROR_KEY_NOT_FOUND)
        else
            {
        {
                // no more keys
            // keys request failed
                llSay(0, "No more keys" );
            llSay(0, "Key-value failed to request keys: " + llList2String(result, 1) );
            }
         }
            else
     }  
            {
}</lsl>}}
                // keys request failed
                llSay(0, "Key-value failed to request keys: " + llGetExperienceErrorMessage(llList2Integer(result, 1)) );
            }
         }  
     }
}</source>
|cat1=Experience
|cat2=Dataserver
|cat3=Experience/Data
|caveats=* It is recommended that keys do not contain commas due to this function returning keys in CSV format.
}}

Latest revision as of 13:21, 21 January 2016

Summary

Function: key llKeysKeyValue( integer first, integer count );

Start an asynchronous transaction to request a number of keys from the script's Experience.
Returns a handle (a key) that can be used to identify the corresponding dataserver event to determine if this command succeeded or failed.

• integer first Zero-based index of the first key to retrieve
• integer count Number of keys to retriever

This function will attempt to retrieve the number of keys requested but may return less if there are not enough to fulfill the full amount requested or if the list is too large. The length of the returned list is limited to 4097 characters (the success flag "1" and 4096 characters). The order keys are returned is not guaranteed but is stable between subsequent calls as long as no keys are added or removed.
The error XP_ERROR_KEY_NOT_FOUND is returned if there index given is greater than or equal to the number of keys.

For this function to work, the script must be compiled into an Experience.

Specification

Dataserver

The dataserver callback parameters are:

String Components
• integer success A boolean specifying if the transaction succeeded (1) or not (0).
• integer error An XP_ERROR_* flag that describes why the operation failed.
• list keys A list of keys (strings) used in the key-value store

Caveats

  • If you recompile a script that was previously associated with an Experience but do so with a client that lacks the ability to compile scripts into an experience the script will lose the associated Experience.
  • It is recommended that keys do not contain commas due to this function returning keys in CSV format.

Examples

key trans;
default
{
    state_entry()
    {
        // retrieve the first 10 keys
        trans = llKeysKeyValue(0, 10);
    }

    dataserver(key t, string value)
    {
        if (t == trans)
        {
            // our llKeysKeyValue transaction is done
            list result = llCSV2List(value);
            if (llList2Integer(result, 0) == 1)
            {
                llSay(0, "Keys retrieved: "+(string)llGetSubString(value, 2, -1));
            }
            else if (llList2Integer(result, 1) == XP_ERROR_KEY_NOT_FOUND)
            {
                // no more keys
                llSay(0, "No more keys" );
            }
            else
            {
                // keys request failed
                llSay(0, "Key-value failed to request keys: " + llGetExperienceErrorMessage(llList2Integer(result, 1)) );
            }
        } 
    }
}

Notes

Compiling

For a script to be associated with an Experience...

  • It must be compiled with a client that is Experience aware,
  • The "Use Experience" checkbox must be checked,
  • And one of the users Experience keys selected.
KBcaution.png Important: Not all TPVs have this functionality.

Deep Notes

Signature

function key llKeysKeyValue( integer first, integer count );