Jump to content

Need help with a Quote on Touch Script.


Sky Linnaeus
 Share

You are about to reply to a thread that has been inactive for 3985 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);
}
}
}

Link to comment
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

Link to comment
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));}

 

 

 

Link to comment
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
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3985 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...