Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Notecard Help

Kimmy Gable
Registered User
Join date: 8 Apr 2006
Posts: 14
11-27-2009 02:21
Hello, I got most of this script off the forums, I am trying to make it so that when a person changes a notecard and drops it in the object it will delete the notecard in the object and replace it with the new. The object is copy only so allowinventory drop was needed. I just can't figure out how to make it so that when you drop a new notecard in it reads and deletes it. Any help would be great!

string sNotecard;
integer iLine = 0;
key kID;
integer ch=34533;
key NoteCard;
string note_name;
integer noteline_index;
list notecard_info;

key owner;
ready(string str){

llRemoveInventory(note_name);
}
default
{
changed(integer c) {
if (c & CHANGED_INVENTORY){llInstantMessage(llGetOwner(),"Tuning for driver "+llKey2Name(llGetOwner())+"...";);llResetScript();
{
// reset script if inventory has been changed
if(c&CHANGED_INVENTORY) llResetScript();
}
}
}
state_entry()
{ owner=llGetOwner();
llAllowInventoryDrop(TRUE);
note_name=llGetInventoryName(INVENTORY_NOTECARD,0);
if(note_name!="";){ NoteCard = llGetNotecardLine(note_name, noteline_index);}
//check if a notecard exists
if(llGetInventoryNumber(INVENTORY_NOTECARD)==0)
{
llSay(0, "No notecard found!";);
return;
}


//get the name of the first notecard
sNotecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
iLine = 0;
//request first line. This calls the dataserver event:
kID = llGetNotecardLine(sNotecard, iLine);
}

dataserver(key query_id, string data)
{
//check if what we got is what we want
if (query_id == kID)
{
//end of file?
if (data != EOF)
{
//put your routines here, e.g.
llSetObjectDesc(data);
//if you expect only one line, you can stop here,
//no need to request the next line
//we include it here though for completeness
}
else // request next line
{
++iLine;
kID = llGetNotecardLine(sNotecard, iLine);
}
}
}
}
Indeterminate Schism
Registered User
Join date: 24 May 2008
Posts: 236
11-27-2009 03:02
"delete the notecard in the object and replace it with the new" is a different, and much harder game than "it reads and deletes it", which is below. Please note that CHANGED_INVENTORY only works if it's the owner that changes inventory, so you also have to check for CHANGED_ALLOWED_DROP. If you only want the owner to be able to change inventory then you don't need the llAllowInventoryDrop(TRUE) because the owner can always edit contents. Also note that anyone can drop anything into contents once llAllowInventoryDrop() is set to TRUE, so the 'CleanMe' function provided here deletes EVERYTHING in contents apart from the script itself. Finally, please note that this version is a bit simplified from yours and doesn't check for a notecard as soon as it starts or record the owner-key.

integer LineNo;
key RequestID;

CleanMe()
{
LineNo = llGetInventoryNumber(INVENTORY_ALL);
while (LineNo)
{
if (llGetInventoryName(INVENTORY_ALL, --LineNo) != llGetScriptName())
{
llRemoveInventory(llGetInventoryName(INVENTORY_ALL, LineNo));
}
}
}

default
{
changed(integer Change)
{
if ((Change & CHANGED_INVENTORY)
|| (Change & CHANGED_ALLOWED_DROP))
{
if (llGetInventoryNumber(INVENTORY_NOTECARD) > 0)
{
LineNo = 0;
RequestID = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD, 0), LineNo);
}
else
{
CleanMe();
}
}
}

dataserver(key ResponseID, string Data)
{
if (ResponseID == RequestID)
{
if (Data == EOF)
{
CleanMe();
}
else
{
// Do whatever it is you want to do with the notecard data
RequestID = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD, 0), ++LineNo);
}
}
}

state_entry()
{
llAllowInventoryDrop(TRUE);
}
}
Kimmy Gable
Registered User
Join date: 8 Apr 2006
Posts: 14
Thanks
11-27-2009 03:11
Thanks I will try this out!
Kimmy Gable
Registered User
Join date: 8 Apr 2006
Posts: 14
Works kinda.
11-27-2009 03:21
Well you weren't kidding about it deleteing everything in the inventory! I moded it abit and it works great now. I have other things inside of the obeject that I Can't have deleted or the object won't work. So I guess the issue I am faced with is this. This is an object that will be for sale. The notecard it reads just changes settings in the object, so since the object is copy only I have to allow inventory drop. Here is the code below that I changed from yours.
I just changed it so that it would only delete the note cards. And it seems to work great, I was able to just drop the notecard on the object and it changed the settings perfecly. But if this leaves it open so that ANYONE can drop things in this will be an issue.
CODE

integer LineNo;
key RequestID;

CleanMe()
{
LineNo = llGetInventoryNumber(INVENTORY_NOTECARD);
while (LineNo)
{
if (llGetInventoryName(INVENTORY_NOTECARD, --LineNo) != llGetScriptName())
{
llRemoveInventory(llGetInventoryName(INVENTORY_NOTECARD , LineNo));
}
}
}

default
{
changed(integer Change)
{
if ((Change & CHANGED_INVENTORY)
|| (Change & CHANGED_ALLOWED_DROP))
{
if (llGetInventoryNumber(INVENTORY_NOTECARD) > 0)
{
LineNo = 0;
RequestID = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD, 0), LineNo);
}
else
{
CleanMe();
}
}
}

dataserver(key ResponseID, string Data)
{
if (ResponseID == RequestID)
{
if (Data == EOF)
{
CleanMe();
}
else
{
// Do whatever it is you want to do with the notecard data
RequestID = llGetNotecardLine(llGetInventoryName(INVENTORY_NOTECARD, 0), ++LineNo);
llSetObjectDesc(Data);
}
}
}

state_entry()
{
llAllowInventoryDrop(TRUE);
}
}
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
11-27-2009 06:38
From: Kimmy Gable
The object is copy only so allowinventory drop was needed.


From: Indeterminate Schism
If you only want the owner to be able to change inventory then you don't need the llAllowInventoryDrop(TRUE) because the owner can always edit contents.


the owner (end buyer) can't edit the contents of a prim if the prim is no mod, that includes mod scripts and notecards inside the no mod prim

if you really want the user to change script functions through a notecard, you would need to make the object mod as well.......or......

use a relay prim. a seperate, modifiable object to hold the notecard. it can read the notecard and then relay the data to the no-mod object

or you can also reference a notecard by its UUID, so it doesn't actually have to be in the object that's reading it. so what you could do is when it detects a change in the notecard it can communicate the new uuid(the uuid changes every time a notecard is changed) to the no mod object, and then the no mod object can go through the routine of getting the notecard data
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Kimmy Gable
Registered User
Join date: 8 Apr 2006
Posts: 14
Sorta Right
11-27-2009 18:37
Yes the end user can mod the notecard, But adding it back to the NO MOD object they can't do.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
11-27-2009 21:26
From: Kimmy Gable
Yes the end user can mod the notecard, But adding it back to the NO MOD object they can't do.

yep, that's why i was correcting indeterminate. you do need llAlowInventoryDrop if you want the object to read it directly from its contents.
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369