Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help me with this script, please.

Zing Ping
Registered User
Join date: 3 Jul 2006
Posts: 8
07-03-2006 11:01
I am using Hank Ramos' notecard reader script. For some reason it is reading the first line twice. Here's the script:

CODE
//Read Notecard DataServer Example
//by Hank Ramos
string notecardName = "My Notecard";
integer lineCounter;
key dataRequestID;

default
{
state_entry()
{
llSay(0, "Ready. Click to start.");
}
touch_start(integer num_detected)
{
state readNotecard;
}
}

state readNotecard
{
state_entry()
{
lineCounter = 0;
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}
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)
{
//If we haven't reached the end of the file
//Display the incoming data, then request the next line #
if (data != EOF)
{
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
lineCounter += 1;
llSay(0, "Line #" + (string)lineCounter + ": " + data);
}
else
{
state default;
}
}
}
}
Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
Maybe
07-03-2006 11:25
Don't know if this is the problem but in the note card reader version I just looked at on the Wiki instead of the line you have


lineCounter += 1;

it is

lineCounter++;
Zing Ping
Registered User
Join date: 3 Jul 2006
Posts: 8
07-03-2006 11:29
I made that change, and the output of the script above is still:

From: someone

[11:27] Read Notecard DataServer Example: Ready. Click to start.
[11:28] Read Notecard DataServer Example: Line #1: Line One
[11:28] Read Notecard DataServer Example: Line #2: Line One
[11:28] Read Notecard DataServer Example: Line #3: Line Two
[11:28] Read Notecard DataServer Example: Line #4: Line Three


The notecard is:

From: someone

Line One
Line Two
Line Three
Ken Freeman
Registered User
Join date: 14 Apr 2006
Posts: 14
07-03-2006 11:32
Try this:

if (data != EOF)
{
llSay(0, "Line #" + (string)lineCounter + ": " + data);
lineCounter += 1;
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}
Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
07-03-2006 11:33
in state_entry, you need lineCounter to be lineCounter++, otherwise it requests line 0 twice
Ken Freeman
Registered User
Join date: 14 Apr 2006
Posts: 14
07-03-2006 11:38
You "primed" the pump so to speak in "entry", so in "dataserver" you should print the line, increment, and then prime the pump again.

Do your work with the data you received, bump your counters, and then ask for more data.

You are doing the reverse.
Zing Ping
Registered User
Join date: 3 Jul 2006
Posts: 8
07-03-2006 11:40
Thanks everyone got it working. The script I posted was the out-of-the-box sample script. I'm new to LSL, but you guys helped me get it working, thanks!
Ken Freeman
Registered User
Join date: 14 Apr 2006
Posts: 14
07-03-2006 11:52
Post the answer please that got it to work!
Zing Ping
Registered User
Join date: 3 Jul 2006
Posts: 8
07-03-2006 12:15
It was your corrected code, Ken, that got it to work. The script outputs the first line as "Line #0" though, but that is normal since counting in LSL (and many languages) starts at 0.
Ken Freeman
Registered User
Join date: 14 Apr 2006
Posts: 14
07-03-2006 13:41
Thanks Zing, didn't run it myself, so just by reading I thought that was it.

It is interesting that the original comments in the code made the same point:

//Display the incoming data, then request the next line #

.
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
07-04-2006 03:06
the fundamental reason that the opening script didn't work, is that you were issuing the next request for a line, BEFORE you incremented the line counter.
Hank Ramos
Lifetime Scripter
Join date: 15 Nov 2003
Posts: 2,328
07-16-2006 12:47
mmm, that bug has been in that example script or awhile. I updated the place where I distribute my examples. The update is below...

CODE
//Read Notecard DataServer Example
//by Hank Ramos
string notecardName = "My Notecard";
integer lineCounter;
key dataRequestID;

default
{
state_entry()
{
llSay(0, "Ready. Click to start.");
}
touch_start(integer num_detected)
{
state readNotecard;
}
}

state readNotecard
{
state_entry()
{
lineCounter = 0;
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}
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)
{
//If we haven't reached the end of the file
//Display the incoming data, then request the next line #
if (data != EOF)
{
llSay(0, "Line #" + (string)lineCounter + ": " + data);
lineCounter += 1;
dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}
else
{
state default;
}
}
}
}
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
04-12-2007 04:52
before i say anything and risk getting flamed for it yes i know i am a noob

with that out of the way how would i get this to say a random line of text from the notecard ??
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
04-12-2007 05:09
You wouldn't. This script is designed to go line by line until it reaches the end and does not care how many lines are in the notecard.

You would have to use llGetNumberOfNotecardLines and llFrand to randomly select a line to grab that falls in the valid range.

Not tested but should work fine, replace llSay with what you want to do:
CODE

integer lines;
key queryID;
string ncName="some notecard";

default{
state_entry(){
llGetNumberOfNotecardLines(ncName);
}

dataserver(key id, string data){
if(id!=queryID)
lines=(integer)data;
else
llSay(0,data);
}

touch_start(integer touches){
queryID=llGetNotecardLine(ncName, llFloor(llFrand(lines)));
}
}


Edit: changed floor to llFloor and fixed formatting.
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
04-12-2007 18:57
thanks loads i will give this a go as soon as i get home in the morning
Ed Gobo
ed44's alt
Join date: 20 Jun 2006
Posts: 220
04-13-2007 04:59
Putting in some spaces to make it more readable would never hurt and it makes the board happier, eg:
CODE
queryID = llGetNotecardLine (ncName, floor (llFrand (lines))); 
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
04-13-2007 05:37
for some reason it keeps telling me name not defined within scope
Ricky Yates
(searching...)
Join date: 28 Jan 2007
Posts: 809
04-13-2007 06:02
Helping would be easier if you could attach the script ... ;)
Goosey Gealach
Where'd my 'yo' go?
Join date: 12 Sep 2006
Posts: 80
04-13-2007 06:06
And much easier if you could put the line and column numbers you get with the error as well.
Sys Slade
Registered User
Join date: 15 Feb 2007
Posts: 626
04-13-2007 06:31
Sorry, I think I know where the problem is.

Change floor( to llFloor( and that should make it happy :)
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
04-13-2007 20:51
sorry about the confussion and thanks for help
Max Shenzhou
Registered User
Join date: 6 Nov 2006
Posts: 2
04-18-2007 04:30
It's possible to read lines from two notecards?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-18-2007 04:41
From: Max Shenzhou
It's possible to read lines from two notecards?


Yes, simply request from both notecards and use different query id's to track which result you get back. Remember however that you will not know which order you will get the replies back in!

Code Fragment
CODE

dataRequestID1 = llGetNotecardLine(notecardName1, lineCounter1);
dataRequestID2 = llGetNotecardLine(notecardName2, lineCounter2);


dataserver(key id, string data)
{
if(id == dataRequestID1) ProcessNotecard1(data);
else if(id == dataRequestID2) ProcessNotecard2(data);
}
Max Shenzhou
Registered User
Join date: 6 Nov 2006
Posts: 2
04-18-2007 05:12
And can I have a second " dataserver(key query_id, string data) " in other state? or the two notecards must be called in the same event?

Thank you
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
04-18-2007 08:16
From: Max Shenzhou
And can I have a second " dataserver(key query_id, string data) " in other state? or the two notecards must be called in the same event?

Thank you



You have to have a dataserver event in each state that is expecting to handle dataserver replies.