Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Read one line of a notecard

Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
12-17-2005 13:19
I would just like a notecard, to be able to be read and for a script to be able to define something using that line, A settings notecard!

integer time = notecardline 1

Or something, i have tried experimenting with the dataserver, but i cant get my head around it.

Thanks for any help in advanced.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-17-2005 13:59
here is a simple script that reads a notecard (that can be found on the wiki: llGetNotecardLine)
CODE

string gName = "Testnotecard"; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries

default {
state_entry() {
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
llSay(0, (string)line+": "+data); // output the line
++gLine; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request next line
}
}
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
12-17-2005 14:45
Checked that, it does every line :/ no worrys ill knock on.
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
12-17-2005 18:43
To only read one line of the notecard, change the code just a bit...

CODE

string gName = "Testnotecard"; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries

default {
state_entry() {
gQueryID = llGetNotecardLine(gName, gLine); // request first line
}

dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF)
{
llSay(0, (string)line+": "+data);
}
}
}
}


BAsically...just take the read all lines loop out.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Zar Zadoq
Learning the Second Life
Join date: 8 Nov 2004
Posts: 21
12-18-2005 15:16
Am I missing something?

Where did the variable "line" come from in the llSay statement:
CODE
                llSay(0, (string)line+": "+data);    


Is that a type for gLine? Or am I just not understanding or missing something?

I see its the same in the Wiki example, so I presume I'm missing something and its not a typo...

But would like someone to tell me what I'm missing!

Thanks! :confused:
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-18-2005 15:58
i'm very sorry about that, your right it should be gLine, i've corrected the example

CODE

string gName = "Testnotecard"; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries

default {
state_entry() {
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
llSay(0, (string)gLine+": "+data); // output the line
++gLine; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request next line
}
}
}
}
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Sol Columbia
Ding! Level up
Join date: 24 Sep 2005
Posts: 91
12-19-2005 10:15
Well, I had the same problem getting a grip on how it works, so I'll share too in a bit more direct way than using the wiki example. I think it makes more sense to see a couple lines than just one, but just cut out the extra to get what you need.

Say you want to read line numbers 2 and 4....


CODE

string card_name = "your_notecard";
key query_line_two; //create a query id for line two
key query_line_four; //create a query id for line four

default
{
state_entry()
{
//Here we set up two queries to the notecard. One to line 2, one to line 4
query_line_two = llGetNotecardLine(card_name, 2); // request line 2
query_line_four = llGetNotecardLine(card_name, 4); //Same deal, line 4
}

dataserver(key query_id, string data)
{
//What to do when you "run" your queries
//The if statement checks to see which query you want by comparing keys
//of course, in the state entry we've said we want both, so as each request
//is processed, the correct action is taken
//You could add an "if (data != EOF)" if you wanted, but it's redundant IMO
//since you are calling a known line

if (query_id == query_line_two) llSay(0, "line two: " + data);
else if (query_id == query_line_four) llSay(0, "line four: " + data);

}
}



I hope this makes sense and is a bit more intuitive.

-Sol

Edit: Fixed typo
Zar Zadoq
Learning the Second Life
Join date: 8 Nov 2004
Posts: 21
12-19-2005 10:59
You guys are just pulling my leg right, (thouh I know how hard it is to avoid typos :-)

I presume Sol wanted to say instead of:



CODE

query_line_two = llGetNotecardLine(card_name, 2); // request line 2
query_line_two = llGetNotecardLine(card_name, 4); //Same deal, line 4


Sol had a typo for the second line and meant to say:

CODE

query_line_two = llGetNotecardLine(card_name, 2); // request line 2
query_line_four = llGetNotecardLine(card_name, 4); //Same deal, line 4
Sol Columbia
Ding! Level up
Join date: 24 Sep 2005
Posts: 91
12-19-2005 12:29
Oops, yes. Thank you. Cut/paste can also be your enemy! =)
Fixed it in the code.

-Sol