Kaitlynn Rainforest Posted April 24, 2011 Share Posted April 24, 2011 I found this script but when i go use it it will only read the first line of the notecard. I'm looking for a script that says a random line when its touch//this script will grab and chat a random line from the "words1" notecard each time the prim is touched.string card = "words1";key linecountid;key lineid;integer linemax;integer random_integer( integer min, integer max ){ return min + (integer)( llFrand( max - min + 1 ) );}default{ state_entry() { //get the number of notecard lines linecountid = llGetNumberOfNotecardLines(card); } touch_start(integer total_number) { lineid = llGetNotecardLine(card, random_integer(0, linemax)); } dataserver(key id, string data) { if (id == linecountid) { linemax = (integer)data - 1; } else if (id == lineid) { llSay(0, data); } }} Link to comment Share on other sites More sharing options...
Talarus Luan Posted April 24, 2011 Share Posted April 24, 2011 Looks correct to me. Did you put the notecard into the object after you saved/reset the script? It only gets the notecard length when the script is reset. Only other thing I can think of is the notecard only has one line in it. Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 24, 2011 Share Posted April 24, 2011 That's odd. There's nothing wrong with the script, as far as I can see. There may be something wrong with your notecard, however. Just to check, try inserting a new diagnostic line in your script ...... dataserver(key id, string data) { if (id == linecountid) { linemax = (integer)data - 1; llOwnerSay("There are " + (string)data + " lines on this card."); // This is the new line } Each line on your notecard should end when you hit the Enter key. If you haven't done that, then you may see many lines of text because they wrap around, but they are really all part of a single long line. If this diagnostic statement says that there's only one line of text on your card, you'll know what's wrong. Link to comment Share on other sites More sharing options...
PeterCanessa Oh Posted April 25, 2011 Share Posted April 25, 2011 llGetNumberOfNotecardLines() is SLOW! Are you giving it enough time before touching the prim to test it? If not the linemax won't yet have been set and you'll be picking a random number between 0 and 0 which might be, for instance, er ... 0, ie; the first line of the notecard. Rolig's suggestion will also tell you when the value has been set and the script is ready for a touch. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted April 25, 2011 Share Posted April 25, 2011 I can't see what''s wrong with it, either. For what it's worth, whenever I've made this sort of thing, I've done it rather differently -- read the whole notecard into a list at one go, randomise the list, and then work my way down it, chatting out the next line in order when the prim is touched. When I reach the end of the list, I randomise it again and start over. So I only actually read the notecard once (or if the contents are changed, of course). It's not really random, but since I'm making a toy rather than an experiment in probabilities I don't really worry -- it chats stuff in a different order each time and it doesn't keep repeating the same thing, which is all I'm really worried about. Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted April 25, 2011 Share Posted April 25, 2011 Simply pass post you NC here - the reason it doesn't work got to be in there. Apart from that, I would read the list once, too and then randomize the list. Since I'm lazy, I would just use llListRandomize Link to comment Share on other sites More sharing options...
Innula Zenovka Posted April 25, 2011 Share Posted April 25, 2011 I stopped simply randomizing the list each time because I grew tired of explaining to people that the fact "it sometimes says the same thing three or four times in a row" certainly doesn't necessarily mean "the script you gave me doesn't work properly". Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 25, 2011 Share Posted April 25, 2011 I agree. There's a 0.1 second delay every time you call llGetNotecardLine or llGetNumberOfNotecardLines. That may not sound like much for a single line, but if you have even ten lines on a card, that's a full second of delay. You might as well do all that reading once in a setup routine and get it out of the way. My own preferred method would be to read the NC lines into a list and then say random ones with llSay(0,llList2String(my_list, (integer)llFrand(len))) , where len = llGetListLength(my_list). Link to comment Share on other sites More sharing options...
PeterCanessa Oh Posted April 25, 2011 Share Posted April 25, 2011 That 0.1s is the artificial delay LSL adds to the processing. Dataserver events can be slow anyway and take some time before the data is actually delivered. Link to comment Share on other sites More sharing options...
Rolig Loon Posted April 25, 2011 Share Posted April 25, 2011 Yup. I should have been clearer that the sum of 0.1 second delays is the minimum that the script will experience. All the more reason for loading the notecard lines once and being done with it. Link to comment Share on other sites More sharing options...
erlebacher1 Posted May 3, 2011 Share Posted May 3, 2011 I am also stuck with the impossibility of reading line 2 from a notecard on the first shot. Of course, one can read the entire notecard. But I have not yet seen a single example that demonstrates reading lines out of order. Thus there should be no need for the second argument of llGetnotecardLine(name, line_nb). Could somebody please post the simplest possible example of reading a single line from a notecard, which is not the first line. Clearly, the note card must be read sequentially, since each line has arbitrary length. Thanks, Gordon Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted May 3, 2011 Share Posted May 3, 2011 I'm not sure if I understand you correctly, but of course you can use llGetNotecardLine to read the lines in any order. There are many examplesa out there where programmers have sprcific information in a specific line and read just that by providing the the line to read and not read all lines before that Link to comment Share on other sites More sharing options...
Rolig Loon Posted May 3, 2011 Share Posted May 3, 2011 Line length makes no difference at all. The end of a line is marked by a line feed/CR. If you want to read line #2 on a card named gCard, write gCardQuery = llGetNotecardLine(gCard,2); Then dataserver(key QiD, string data){ if ( QiD == gCardQuery) { if (data != EOF) { llOwnerSay("This is line #2: " + data); } }} ETA: I feel silly asking, but you are hitting ENTER at the end of each line you type on the notecard, right? Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now