Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need Help with a note-card reader

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-17-2006 07:57
I've never really dealt with the data server event, and for some reason this script only runs the first time someone touches it. It will only work after it's reset again. Can someone point out what I did wrong? the basic note card reading script I pulled from the wiki, and I modified it with (what I thought) was a functional comparison if statement.

in a nut shell, this (is supposed to) read a list of names from a note-card. if the person touching the object is somewhere on the list, it will do one set of commands (in this case, things to open a door). if they are not on the list it will do another set of commands (ring the doorbell).

CODE

// Read out a complete notecard from the object's inventory.
string gName; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries
string opener;

integer access;

open()
{
//llWhisper(0,"Opening Door");//Debugging Shiz
llMessageLinked(LINK_THIS,0,"open",NULL_KEY);
llPlaySound("Door move",1);
}



default
{
touch_start(integer num)
{
opener=llDetectedName(0);
gName = llGetInventoryName(INVENTORY_NOTECARD, 0); // select the first notecard in the object's inventory
gQueryID = llGetNotecardLine(gName, gLine); // request first line
}



dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF)
{ // not at the end of the notecard
if(opener==data)
{
access=TRUE;
open();
}
++gLine; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request next line
}
}
}
}



if I put a llResetScript in the if(data==EOF) statement, the script will continue to work (since it's being reset once it's all done), but I'd like to know how to fix this script so that I would not need to reset the script at all.

[Edit]Was a little trigger-happy with the ctrl+v[/edit]
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
12-17-2006 09:07
You need to reset gLine to 0 in the touch_start handler. It starts out at 0, but after processing the first person, by the end of all the dataserver calls it ends up at the end of the notecard. So for the next person, you're requesting lines past the end of the notecard.
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
12-17-2006 09:32
From: Ziggy Puff
You need to reset gLine to 0 in the touch_start handler. It starts out at 0, but after processing the first person, by the end of all the dataserver calls it ends up at the end of the notecard. So for the next person, you're requesting lines past the end of the notecard.


thanks :) I seem to have over looked that.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
12-17-2006 09:35
..also, bear in mind that reading Notecards is hideously slow.

For your application I think it would be better to read the Notecard one time into a list and then use llListFindList to check for 'opener' in the list. If the Notecard changes you can use the 'changed' event (check for CHANGED_INVENTORY) to trigger a reread of the Notecard.