Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

basic questions on dynamic inv content

Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-27-2007 02:33
I have some basic questions on loading inventory items dynamically.

How do you read parameters in a notecard into a list or other LSL data structure? For example, how do you count the number of inventory items and dynamically store it in a notecard?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-27-2007 03:51
You cannot write to notecards only read from them.

To read data from a notecard use llGetNotecardLine
The data server will hopefully reply via a dataserver event, I say hopefully because you have no control over if or when it will respond. Because of this its good practise to add a timer when you request data so that you can recover should it stall.


CODE

integer lineCounter = 0;
string notecardName;
key dataRequestID = NULL_KEY;

state ReadNoteCard
{
on_rez(integer num) { llResetScript(); }

state_entry()
{
// reset everything
lineCounter = 0;

// Make sure this is a valid notecard
integer itemtype = llGetInventoryType(notecardName);
if(INVENTORY_NOTECARD == itemtype)
{
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
llSetTimerEvent(10);
}
else
{
llOwnerSay("Error - Notecard " + notecardName + " missing!");
state Running;
}

}

dataserver(key queryid, string data)
{
//Check to make sure this is the request we are making.
//Remember that when data comes back from the dataserver,
//it goes to *all* scripts in your prim.
//So you have to make sure this is the data you want, and
//not data coming from some other script.
if (dataRequestID == queryid)
{
llSetTimerEvent(0);
//If we haven't reached the end of the file
if (data != EOF)
{
// I use ; as comments
if(llGetSubString(data, 0,0) != ";")
{
// process the data
}
lineCounter++;
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
llSetTimerEvent(10);

}
else
{
state Running;
}
}
}

timer()
{
// The notecard read failed so abort
llSetTimerEvent(0);
llOwnerSay("Error reading Data.Aborting.");
state Running;
}

changed(integer change)
{
if(change & CHANGED_INVENTORY)llResetScript();
}
}



Exactly what you do with the data is dependant upon what it contains.
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-27-2007 19:17
is there a way to use LSL to count the number of inventory items of a certain type (say images)?
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
02-27-2007 21:35
From: Ina Centaur
is there a way to use LSL to count the number of inventory items of a certain type (say images)?

llGetInventoryNumber(integer type)
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
02-28-2007 01:31
thanks!

also, how do you make sure no one (other than creator) can add any more items to the object's inventory?
Woopsy Dazy
Registered User
Join date: 12 Nov 2006
Posts: 173
02-28-2007 02:12
llAllowInventoryDrop(FALSE);
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
02-28-2007 10:26
From: Ina Centaur
how do you make sure no one (other than creator) can add any more items to the object's inventory?
This is the default behavior, unless llAllowInventoryDrop( TRUE ) is called.