Notecard Question
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
11-25-2008 11:27
I didn't see anything in the wiki on this, so here goes. When reading a notecard, is there a way to put in comments without it counting as a line? It's not that important, but I'm writing a fairly long notecard (route information for a touring vehicle) and it would help with the accounting if I could write comments on the side.
_____________________
Horses, Carriages, Modern and Historical Riding apparel. Ride a demo horse, play whist, or just loiter. I'm fair used to loiterers. http://slurl.com/secondlife/Caledon%20Eyre/48%20/183/23/
|
|
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
|
11-25-2008 11:53
Before outputting the line to the screen, just pass it through a filter that deletes everything to the right of and including a "//", it's just a string right? If you have this at the top of your script... string comments(string message) { if( llSubStringIndex(message,"//")!=-1 ) { return llDeleteSubString(message,llSubStringIndex(message, "//")-1,llStringLength(message)); } else { return message; } }
Then comments(data) will return a string without your comments.
|
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
11-25-2008 12:10
From: Ee Maculate Before outputting the line to the screen, just pass it through a filter that deletes everything to the right of and including a "//", it's just a string right? If you have this at the top of your script... string comments(string message) { if( llSubStringIndex(message,"//")!=-1 ) { return llDeleteSubString(message,llSubStringIndex(message, "//")-1,llStringLength(message)); } else { return message; } }
Then comments(data) will return a string without your comments.
As far as I know, a valid notecard comment starts with #, not //. I think you can just append # the comment to the end of your notecard lines and just read the characters from llGetNotecardLine() until you reach a # and then stop.
|
|
Jeredin Denimore
Romani Ite Domum
Join date: 5 Jul 2008
Posts: 95
|
11-25-2008 12:17
To be honest, you can use any "control" character you want really. You'll be the one parsing the file hehe 
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
11-25-2008 12:33
I usually parse it out in the dataserver event, something like this: key handle; integer lineNo; ... dataserver(key requested, string data) { handle = null_key; if (data != EOF) { if (llStringLength(data) > 0) // not a blank line if (llSubStringIndex(data, ";"  != 0) // not a comment line { // process a valid line here } ++lineNo; handle = llGetNotecardLine("notecardName",lineNo); } else { //do end of file activities } } I chose the semicolon to represent a comment line above, but it could be anything of your choosing. You could of course add other filters to this like trimming the line first to skip lines that look blank but have spaces only.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
11-25-2008 14:14
if you use a sentinal value (#,//,;, or anything else you like) and you intend to include comments on their own line as well as trailing comments, it's helpful to strip them out before testing for zero line length if (~(vIntCommentIndex = llSubStringIndex( noteline, "#" ))){ //-- found a comment? noteline = llGetSubString( noteline, 0, vIntCommentIndex - 1 ); //-- strip it } if (llStringLength( noteline )){ //-- anything left? //-- use it }
or somesuch parsestring works too but it's overkill for this unless you have inline comments (eg trailing data, usually needs a ending sentinal value)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
11-25-2008 14:26
Thanks all!
_____________________
Horses, Carriages, Modern and Historical Riding apparel. Ride a demo horse, play whist, or just loiter. I'm fair used to loiterers. http://slurl.com/secondlife/Caledon%20Eyre/48%20/183/23/
|