Jump to content

Help with random line script


Kaitlynn Rainforest
 Share

You are about to reply to a thread that has been inactive for 4825 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

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

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

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

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

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

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

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

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

You are about to reply to a thread that has been inactive for 4825 days.

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
 Share

×
×
  • Create New...