Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help! random notecard line reader!

Kim Nolan
Registered User
Join date: 15 Apr 2006
Posts: 5
06-27-2008 21:55
Hi, sorry if I've posted in the wrong place. I'm looking for a random notecard line reader script so when the object it is in is clicked, it will read out a random line from a notecard also in the object. Any idea where I can get one? (which won't cost me millions of lindens!)
Thanks, Kim
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-27-2008 22:17
Below. Note that this hasn't been compiled yet, so it may need minor syntax fixes.

CODE

string NOTECARD_NAME = "quotes";

integer nLines = 0;

key nLinesRequest = NULL_KEY;
key lineRequest = NULL_KEY;

default
{
state_entry()
{
nLinesRequest = llGetNumberOfNotecardLines(NOTECARD_NAME);
}

dataserver(key request, string data)
{
if (request == nLinesRequest)
{
nLinesRequest = NULL_KEY;
nLines = (integer)data;

state ready;
}
}
}

state ready
{
changed(integer changes)
{
if (changes & CHANGED_INVENTORY)
{
state default;
}
}

touch_start(integer nDetected)
{
integer index = (integer)llFrand(nLines);
lineRequest = llGetNotecardLine(NOTECARD_NAME, index);
}

dataserver(key request, string data)
{
if (request == lineRequest)
{
lineRequest = NULL_KEY;

llWhisper(data);
}
}
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-28-2008 08:24
Here is an alternative using a list:
CODE
string cardName = "quotes";
key sdQueryID;
list card_lines;
integer sdLine;

default
{
state_entry()
{
sdLine = 0;
card_lines = [];
if ( llGetInventoryType( cardName ) == INVENTORY_NOTECARD )
sdQueryID = llGetNotecardLine(cardName, sdLine);
}

dataserver(key query_id, string data)
{
if (query_id == sdQueryID)
if (data != EOF)
{
card_lines = (card_lines=[]) + card_lines + data;
sdLine++ ;
sdQueryID = llGetNotecardLine(cardName, sdLine);
}
else llOwnerSay( (string)sdLine+" lines read from card: "+ cardName );
}

touch_start(integer n)
{
integer x = (integer)llFrand( llGetListLength( card_lines ));
llWhisper( PUBLIC_CHANNEL, llList2String( card_lines, x ));
}

changed(integer change)
{
if ( change & CHANGED_INVENTORY ) llResetScript();
}
}
_____________________
From Studio Dora
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
06-28-2008 09:53
Just depending on the number of entries you can also do it easier and with less resources if you just put the lines in a list.

Example script from an old thread:

CODE
list quotelist =[
"To be, or not to be: that is the question. - (Hamlet, Act III, Scene I).",
"Neither a borrower nor a lender be; For loan oft loses both itself and friend, and borrowing dulls the edge of husbandry. - (Hamlet, Act I, Scene III).",
"This above all: to thine own self be true. - (Hamlet, Act I, Scene III).",
"Though this be madness, yet there is method in 't.. - (Hamlet, Act II, Scene II).",
"That it should come to this!. - (Hamlet, Act I, Scene II).",
"There is nothing either good or bad, but thinking makes it so. - (Hamlet, Act II, Scene II).",
"What a piece of work is man! how noble in reason! how infinite in faculty! in form and moving how express and admirable! in action how like an angel! in apprehension how like a god! the beauty of the world, the paragon of animals! . - (Hamlet, Act II, Scene II).",
"The lady doth protest too much, methinks. - (Hamlet, Act III, Scene II).",
"In my mind's eye. - (Hamlet, Act I, Scene II).",
"A little more than kin, and less than kind. - (Hamlet, Act I, Scene II).",
"The play 's the thing wherein I'll catch the conscience of the king. - (Hamlet, Act II, cene II).",
"And it must follow, as the night the day, thou canst not then be false to any man. - (Hamlet, Act I, Scene III).",
"This is the very ecstasy of love. - (Hamlet, Act II, Scene I).",
"Brevity is the soul of wit. - (Hamlet, Act II, Scene II).",
"Doubt that the sun doth move, doubt truth to be a liar, but never doubt I love. - (Hamlet, Act II, Scene II).",
"Rich gifts wax poor when givers prove unkind. - (Hamlet, Act III, Scene I).",
"Do you think I am easier to be played on than a pipe? - (Hamlet, Act III, Scene II).",
"I will speak daggers to her, but use none. - (Hamlet, Act III, Scene II).",
"When sorrows come, they come not single spies, but in battalions. - (Hamlet, Act IV, Scene V).",
"All the world 's a stage, and all the men and women merely players. They have their exits and their entrances - And one man in his time plays many parts - (As You Like It, Act II, Scene VII).",
"Can one desire too much of a good thing?. - (As You Like It, Act IV, Scene I).",
"I like this place and willingly could waste my time in it - (As You Like It, Act II, Scene IV).",
"How bitter a thing it is to look into happiness through another man's eyes! - (As You Like It, Act V, Scene II).",
"Blow, blow, thou winter wind! Thou art not so unkind as man's ingratitude. - (As You Like It, Act II, Scene VII).",
"True is it that we have seen better days. - (As You Like It, Act II, Scene VII). "
];

default {
touch_start(integer total_number){
integer quote = (integer)llFrand(24.0);
llSay(0, llList2String(quotelist, quote));
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Kim Nolan
Registered User
Join date: 15 Apr 2006
Posts: 5
more help needed
06-29-2008 12:55
Hi, thanks everyone for your advice. Unfortunately I can't get any of these to work. I'm sure I'm probably doing something wrong. And copying and pasting the stuff you guys sent me into a new script, then putting it into an object. But, I'm not able to "touch" (click) the oject to activate to scrit you've given me. What am I doing wrong?
Is it something to do with the
CODE
 thingy? Sorry, I'm a novice!
Kim
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
06-29-2008 14:42
the tags with PHP and /PHP are not part of the LSL code
_____________________
From Studio Dora
bargain Walcott
Registered User
Join date: 31 Oct 2005
Posts: 248
02-05-2009 09:28
Niether of the above first 2 scripts seem to work and I can't find the problems.