Difference between revisions of "LlRequestInventoryData"

From Second Life Wiki
Jump to navigation Jump to search
m (Added a note about the scope of the vector returned by using llRequestInventoryData() with a distant landmark following considerable confusion in an inworld scripters group.)
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{LSL_Function/inventory|name|uuid=false}}
{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/inventory|name|uuid=false}}
|func_id=156|func_sleep=1.0|func_energy=10.0
|func_id=156|func_sleep=1.0|func_energy=10.0
|func=llRequestInventoryData
|func=llRequestInventoryData
|return_type=key
|return_type=key
|return_subtype=handle
|p1_type=string|p1_name=name|p1_desc
|p1_type=string|p1_name=name|p1_desc
|func_footnote
|func_footnote
|func_desc=Requests data from objects inventory object. When data is available the [[dataserver]] event will be raised.
|func_desc=Requests data about the item {{LSLP|name}} in the prim's inventory. When data is available the [[dataserver]] event will be raised.
|return_text=that is used to identify the [[dataserver]] event when it is raised.
|Return_text=that is used to identify the [[dataserver]] event when it is raised.
|spec
|spec
|caveats
|caveats=
* The description of the vector returned in the [[dataserver]] event above implies the value is a region coordinate; it in fact represents the distance in meters of the landmark's location relative to <0,0,0> in the region in which the script is running. For a landmark pointing to a location in the current region, that's the same as a region coordinate; however, when used with a landmark pointing to a different region the vector's x and y values can be quite large (and/or negative). The vector is suitable for use in calculating a global coordinate (as above) or a landmark's distance from the object containing the script in the current region or across the entire Second Life grid.
|constants=
|constants=
{{{!}} {{Prettytable}}
{{{!}} {{Prettytable}}
{{!}}-{{Hl2}}
{{!}}-{{Hl2}}
! colspan="2" title="name Inventory Type"{{!}}{{LSL Param|name}} Type
! colspan="2"{{!}} {{LSLPT|name}}'s Inventory Type  
! title="typecast needed to decode the return for the payload of the dataserver event" {{!}} [[dataserver]]
!{{!}} [[dataserver]]
! {{!}} Description
!{{!}} Description
{{!}}-
{{!}}-
{{LSL Constants/llRequestInventoryData}}
{{LSL Constants/llRequestInventoryData}}
{{!}}}
{{!}}}
|examples=
|examples=
<lsl>//-- Open map for owner to 1st landmark in object inventory on touch
<source lang="lsl2">//-- Open map for owner to 1st landmark in object inventory on touch
//-- *MUST* be in an attached object (llMapDestination Requirement for non-touch use)
//-- *MUST* be in an attached object (llMapDestination Requirement for non-touch use)
key vgKeyOwner;
key vgKeyOwner;
Line 47: Line 49:


   on_rez( integer vIntNull )
   on_rez( integer vIntNull )
  {
    llResetScript();
  }
  state_entry()
   {
   {
     vgKeyOwner = llGetOwner();
     vgKeyOwner = llGetOwner();
   }
   }
}</lsl>
}</source>
<lsl>//An easily-configurable teleporter that sets its destination by getting it from a landmark in the prim's inventory
<source lang="lsl2">//An easily-configurable teleporter that sets its destination by getting it from a landmark in the prim's inventory
//Note: this teleporter is subject to the 300m distance limit for llSitTarget
//Note: this teleporter is subject to the 300m distance limit for llSitTarget
//by Ilse Mannonen
//by Ilse Mannonen


//on state entry, request inventory data and set text for first landmark found in inventory.   
//on state entry, request inventory data and set text for first landmark found in inventory.   
    //If none, complain
//If none, complain
//on getting data, set sit target
//on getting data, set sit target
//on change in inventory, reset script
//on change in inventory, reset script
Line 65: Line 71:


key requestid;
key requestid;
vector dest;
vector offset;


default
default
Line 72: Line 76:
     state_entry()
     state_entry()
     {
     {
         //complain if there are no notecards
         //complain if there are no landmarks
         if (llGetInventoryNumber(INVENTORY_LANDMARK) == 0)
         if (llGetInventoryNumber(INVENTORY_LANDMARK) == 0)
         {
         {
Line 80: Line 84:
         {
         {
             //set floating text according to the LM name
             //set floating text according to the LM name
             llSetText("Teleport to " + llGetInventoryName(INVENTORY_LANDMARK, 0), <1,1,1>, 1);
             llSetText("Teleport to " + llGetInventoryName(INVENTORY_LANDMARK, 0), <1.0, 1.0, 1.0>, 1.0);
             //request the LM data
             //request the LM data
             requestid = llRequestInventoryData(llGetInventoryName(INVENTORY_LANDMARK, 0));
             requestid = llRequestInventoryData(llGetInventoryName(INVENTORY_LANDMARK, 0));
Line 90: Line 94:
         if (id == requestid)
         if (id == requestid)
         {
         {
             //data will be in vector format             
             //data will be in vector format
             dest = (vector)data;
             rotation rot = ZERO_ROTATION / llGetRot();
             offset = (dest - llGetPos()) * (ZERO_ROTATION / llGetRot());
             vector dest = (vector)data;
             llSitTarget(offset, llEuler2Rot(<0,-90,0> * DEG_TO_RAD));          
             vector offset = (dest - llGetPos()) * rot;
         }      
             llSitTarget(offset, rot);
         }
     }
     }
      
      
     changed(integer change)
     changed(integer change)
     {
     {
        if (change & CHANGED_LINK)
        { // and it was a link change
            llSleep(0.5); // llUnSit works better with this delay
            key user = llAvatarOnSitTarget();
            if (user) { // somebody is sitting on me
                llUnSit(user); // unsit him
            }
        }
        //when doing "ifs" on bitwise things, it's best to do them separate instead of using else..if,
        //in case you hit the one in a billion chance when the inventory and link changes are reported in the same event.
         if (change & CHANGED_INVENTORY)
         if (change & CHANGED_INVENTORY)
         {
         {
Line 104: Line 119:
             llResetScript();
             llResetScript();
         }
         }
        //when doing "ifs" on bitwise things, it's best to do them separate instead of useing else..if, in case you hit the one in a billion chance when the inventory and link changes are reported in the same event.
        if (change & CHANGED_LINK)
        { // and it was a link change
            llSleep(0.5); // llUnSit works better with this delay
            if (llAvatarOnSitTarget() != NULL_KEY) { // somebody is sitting on me
                llUnSit(llAvatarOnSitTarget()); // unsit him
            }
        }       
     }
     }
      
      
Line 118: Line 125:
         llResetScript();
         llResetScript();
     }
     }
}</lsl>
}</source>
|helpers
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llMapDestination]]|}}
{{LSL DefineRow||[[llMapDestination]]|}}
|also_tests
|also_tests
|also_events
|also_events=
{{LSL DefineRow||[[dataserver]]|}}
|also_articles
|also_articles
|notes
|notes

Revision as of 18:33, 19 February 2018

Summary

Function: key llRequestInventoryData( string name );

Requests data about the item name in the prim's inventory. When data is available the dataserver event will be raised.
Returns the handle (a key) that is used to identify the dataserver event when it is raised.

• string name an item in the inventory of the prim this script is in

name's Inventory Type dataserver Description
Landmark (vector) The vector data received by dataserver is a global position as an offset from the current region's origin (<0,0,0>). To obtain the absolute global position of a landmark, add llGetRegionCorner() to the vector.

Caveats

  • This function causes the script to sleep for 1.0 seconds.
  • If name is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
  • The description of the vector returned in the dataserver event above implies the value is a region coordinate; it in fact represents the distance in meters of the landmark's location relative to <0,0,0> in the region in which the script is running. For a landmark pointing to a location in the current region, that's the same as a region coordinate; however, when used with a landmark pointing to a different region the vector's x and y values can be quite large (and/or negative). The vector is suitable for use in calculating a global coordinate (as above) or a landmark's distance from the object containing the script in the current region or across the entire Second Life grid.
All Issues ~ Search JIRA for related Bugs

Examples

//-- Open map for owner to 1st landmark in object inventory on touch
//-- *MUST* be in an attached object (llMapDestination Requirement for non-touch use)
key vgKeyOwner;

default
{
  touch_start( integer vIntNull )
  {
    if (llDetectedKey( 0 ) == vgKeyOwner)
    {
      integer vIntLMcount = llGetInventoryNumber( INVENTORY_LANDMARK );
       //-- make sure we have a landmark in invetory
      if (vIntLMcount)
      {
        llRequestInventoryData( llGetInventoryName( INVENTORY_LANDMARK, 0 ) );
      }
    }
  }

  dataserver( key vKeyNull, string vStrData )
  {
     //-- because we don't know who touched us in this event, this
     //-- only works for the owner when called from the dataserver
    llMapDestination( llGetRegionName(), (vector)vStrData, ZERO_VECTOR );
  }

  on_rez( integer vIntNull )
  {
    llResetScript();
  }

  state_entry()
  {
    vgKeyOwner = llGetOwner();
  }
}
//An easily-configurable teleporter that sets its destination by getting it from a landmark in the prim's inventory
//Note: this teleporter is subject to the 300m distance limit for llSitTarget
//by Ilse Mannonen

//on state entry, request inventory data and set text for first landmark found in inventory.  
//If none, complain
//on getting data, set sit target
//on change in inventory, reset script
//on sit, TP the person and unsit

//Thanks to Pol Tabla, who wrote the simple sit-teleport script I have adapted here

key requestid;

default
{
    state_entry()
    {
        //complain if there are no landmarks
        if (llGetInventoryNumber(INVENTORY_LANDMARK) == 0)
        {
            llSay(0, "There are no landmarks in me.  You need to put a landmark in me for me to work.");
        }
        else
        {
            //set floating text according to the LM name
            llSetText("Teleport to " + llGetInventoryName(INVENTORY_LANDMARK, 0), <1.0, 1.0, 1.0>, 1.0);
            //request the LM data
            requestid = llRequestInventoryData(llGetInventoryName(INVENTORY_LANDMARK, 0));
        }
    }
    
    dataserver(key id, string data)
    {
        if (id == requestid)
        {
            //data will be in vector format
            rotation rot = ZERO_ROTATION / llGetRot();
            vector dest = (vector)data;
            vector offset = (dest - llGetPos()) * rot;
            llSitTarget(offset, rot);
        }
    }
    
    changed(integer change)
    {
        if (change & CHANGED_LINK) 
        { // and it was a link change
            llSleep(0.5); // llUnSit works better with this delay
            key user = llAvatarOnSitTarget();
            if (user) { // somebody is sitting on me
                llUnSit(user); // unsit him
            }
        }
        //when doing "ifs" on bitwise things, it's best to do them separate instead of using else..if,
        //in case you hit the one in a billion chance when the inventory and link changes are reported in the same event.
        if (change & CHANGED_INVENTORY)
        {
            //reset on inventory change, so people don't have to manually reset when they add a new LM
            llResetScript();
        }
    }
    
    on_rez(integer param)
    {
        llResetScript();
    }
}

See Also

Events

•  dataserver

Functions

•  llMapDestination

Deep Notes

Search JIRA for related Issues

Signature

function key llRequestInventoryData( string name );