A B C D E F G I J K L M N O R S T U V W
Da Do Dr

dataserver(key queryid, string data)

This event handler is triggered when the requested data is returned to the script. Data may be requested using the llGetNotecardLinellGetNumberOfNotecardLinesllRequestAgentDatallRequestInventoryData, and llRequestSimulatorData functions.

The queryid parameter is the key returned by any of these functions. The data parameter is the requested information (see the descriptions of the function calls for information on how to interpret it). The dataserver event is raised for all scripts in the prim. This is why it is necessary to check the query id.

Dataserver answers aren’t necessarily coming in the order they were requested in. So, if there are multiple pending requests, always use the queryid key to determine which answer is being received. If only one request is processed at a time, and only one script is in the prim that uses the dataserver event, this problem doesn’t arise.

Note: Dataserver requests will trigger all dataserver() events in all scripts within the same prim where the request was made. dataserver() events will not be triggered in scripts contained in other prims in the same linked object. This is the same regardless of whether the prim in question is the parent/root prim, or a child.

Remember: Erroneous requests silently fail and never cause a dataserver() event to occur (e.g. if a notecard line is requested, but a key is supplied that isn’t pointing to a notecard). A timer could catch these silent failures by checking to see if no dataserver() event has occured after a defined time.

The dataserver is rather slow, so keep this in mind when using the aforementioned functions.

Functions:

Function Description
llGetNotecardLine Requests the content of a given line in a notecard.
llGetNumberOfNotecardLines Requests the total number of lines in a notecard.
llRequestAgentData Requests an agent’s online status, name, account creation date, or rating.
llRequestInventoryData Currently limited to getting a position from a landmark.
llRequestSimulatorData Requests status, position, and rating (PG/Mature) of a sim.

Example:

key request;

default 
{
    state_entry() 
    {
        request = llRequestAgentData(llGetOwner(), DATA_BORN); // request your SL creation date
    }
    
    dataserver(key queryid, string data) 
    {
        if( request == queryid )
            llSay(0, "You were born on " + data);
    }
}
Example of working with multiple requests: KriAyakashi
list avatars;
list requests;
key avatar;

default
{
   state_entry()
   {
       llSensor("", NULL_KEY, AGENT, 96.0, PI);
   }

   sensor(integer num_detected)
   {
      integer i;
      avatars = [];
      requests = [];
      for(i=0; i<num_detected; ++i)
      {
         avatar = llDetectedKey( i );
         avatars  += [avatar]; // to use less memory use this hack: avatars = (avatars=[]) + avatars + [avatar];
         requests += [llRequestAgentData(avatar, DATA_BORN)]; // to use less memory use this hack: requests = (requests=[]) + requests + [llRequestAgentData(llDetectedKey(i), DATA_BORN)];    
      }
   }

   dataserver(key queryid, string data)
   {
       integer idx = llListFindList(requests, [queryid]);
       avatar = llList2Key(avatars, idx); // as we added the requests in the same order as avatars
       llOwnerSay(llKey2Name(avatar)+" was born "+data);
   }
}

 

Another Example

key queryFromThisScript;

default {
    state_entry() {
        queryFromThisScript = llGetNotecardLine("notecard", 0);
    }

    dataserver(key query_id, string data) {
        if (query_id == queryFromThisScript) {
            llOwnerSay(data);
        }
    }
}