Jump to content
Sign in to follow this  
Sky Linnaeus

Need help with a Quote on Touch Script.

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

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

Recommended Posts

I have this script from the script library and it does pretty much what I need it to do. Except I need it to say the quotes randomly instead of in order. Can anyone help? I'm a total lost cause when it comes to scripting. Thanks in advance!

 

// Touch a quote script
// By CodeBastard Redgrave
// Reads quotes from a notecard and displays them sequentially when you touch!
// BEWARE it cannot handle quotes more than 256 characters. Split them into multiple lines if needed.

// This is a free script, DO NOT RESELL!
// It's loosely based on the classic dataserver script from the LSL wiki.
// Feel free to modify it to make your own book! Make code not war <3

string notecardName = "Quotes";

integer currentLine;
key notecardRequestID;

integer quoteIndex;
integer numberOfQuotes;
list listOfQuotes;

init()
{
integer numberOfNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);

if (numberOfNotecards)
{
currentLine = 0;
notecardRequestID = llGetNotecardLine(notecardName, currentLine);

llOwnerSay("Loading notecards now...");
}
}

default
{
on_rez(integer start_param)
{
llResetScript();
}

changed(integer change)
{
if (change & CHANGED_INVENTORY)
llResetScript();
}

state_entry()
{
init();
}

touch_start(integer num_detected)
{
llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));

if (numberOfQuotes <= ++quoteIndex)
quoteIndex = 0;

}

dataserver(key id, string data)
{
notecardRequestID = NULL_KEY;

if (data == EOF)
{
currentLine = 0;

numberOfQuotes = llGetListLength(listOfQuotes);
integer freeMemory = llGetFreeMemory();

llOwnerSay("Done loading notecards!\n"
+ (string)numberOfQuotes + " quotes loaded, free memory " + (string)freeMemory);
}
else
{
if (data != "")
listOfQuotes += [data];

notecardRequestID = llGetNotecardLine(notecardName, ++currentLine);
}
}
}

Share this post


Link to post
Share on other sites
// Touch a quote script// By CodeBastard Redgrave// Reads quotes from a notecard and displays them randomly when you touch!// BEWARE it cannot handle quotes more than 256 characters. Split them into multiple lines if needed.// This is a free script, DO NOT RESELL!// It's loosely based on the classic dataserver script from the LSL wiki.// Feel free to modify it to make your own book! Make code not war <3string notecardName = "Quotes";integer currentLine;key notecardRequestID;integer quoteIndex;integer numberOfQuotes;list listOfQuotes;init(){	integer numberOfNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);	if (numberOfNotecards)	{		currentLine = 0;		notecardRequestID = llGetNotecardLine(notecardName, currentLine);		llOwnerSay("Loading notecards now...");	}}default{	on_rez(integer start_param)	{		llResetScript();	}	changed(integer change)	{		if (change & CHANGED_INVENTORY)			llResetScript();	}	state_entry()	{		init();	}	touch_start(integer num_detected)	{		quoteIndex = (integer)llFrand(numberOfQuotes + 1);		llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));	}	dataserver(key id, string data)	{		notecardRequestID = NULL_KEY;		if (data == EOF)		{			currentLine = 0;			numberOfQuotes = llGetListLength(listOfQuotes);			integer freeMemory = llGetFreeMemory();			llOwnerSay("Done loading notecards!\n"				+ (string)numberOfQuotes + " quotes loaded, free memory " + (string)freeMemory);		}		else		{			if (data != "")				listOfQuotes += [data];			notecardRequestID = llGetNotecardLine(notecardName, ++currentLine);		}	}}

 Just change the touch_start event

Share this post


Link to post
Share on other sites

Just replace

touch_start(integer num_detected){    llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));    if (numberOfQuotes <= ++quoteIndex)    quoteIndex = 0;}

with

 

touch_start(integer num_detected){    quoteIndex = (integer)llFrand(numberOfQuotes);    llSay(PUBLIC_CHANNEL, llList2String(listOfQuotes, quoteIndex));}

 

 

 

Share this post


Link to post
Share on other sites

ha ha , my bad . I have been too fast 

llFrand need a +1 when we want an integer because there is 1/2^32 possibilty to get the upper limit.

But the number of lines are already +1 compared to the upper index of the list

You are right

Share this post


Link to post
Share on other sites

I made this litle quote script once:

string NoteName;integer Lines;key count;key quote;default {    state_entry() {        NoteName = llGetInventoryName(INVENTORY_NOTECARD,0);        count = llGetNumberOfNotecardLines(NoteName);    }        touch_start(integer total_number) {        integer line = (integer)llFrand(Lines);        quote = llGetNotecardLine(NoteName, line);    }    dataserver( key query_id, string data) {        if(query_id == count) Lines = (integer)data;        else if (query_id == quote) {            string name = llGetObjectName();            llSetObjectName(" ");            llSay (0, data);            llSetObjectName(name);        }    }        changed(integer change) {        if (change & CHANGED_INVENTORY) llResetScript();    }}

 It uses less memory as it does not use a list to store all the notecard lines.
Allthough I don´t really know if the use of the dataserver at every touch might be worse :)

  • Like 1

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 2605 days.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...