Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

help with saying target

Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
05-07-2007 09:07
hey guys i got the randome note card reader and i am wanting to drop it in something that will read a randome line of the notecard text (which i already have) but if that line contains say %t it would say the persons name who touched the item
and if it were to have %o in the line it would say the owners name

i have messed around with a couple of scripts and i can get a touched onject to spout out the owners name and the touchers name but i just have no clue how to do this on a special que from what it reads in the note card

any help ?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-07-2007 09:46
From: Bizcut Vanbrugh
hey guys i got the randome note card reader and i am wanting to drop it in something that will read a randome line of the notecard text (which i already have) but if that line contains say %t it would say the persons name who touched the item
and if it were to have %o in the line it would say the owners name

i have messed around with a couple of scripts and i can get a touched onject to spout out the owners name and the touchers name but i just have no clue how to do this on a special que from what it reads in the note card

any help ?



CODE

string Replace(string text, string replace, string with)
{
integer lenreplace = llStringLength(replace);

index = llSubStringIndex(text, replace);
while(index >= 0)
{
integer len = llStringLength(text);
phrase = llGetSubString(yexy, 0, index - 1 ) + with + llGetSubString(text, index + lenreplace , len);
index = llSubStringIndex(text, replace);
}
return text;
}
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
05-08-2007 02:58
From: Newgate Ludd
CODE

string Replace(string text, string replace, string with)
{
integer lenreplace = llStringLength(replace);

index = llSubStringIndex(text, replace);
while(index >= 0)
{
integer len = llStringLength(text);
phrase = llGetSubString(yexy, 0, index - 1 ) + with + llGetSubString(text, index + lenreplace , len);
index = llSubStringIndex(text, replace);
}
return text;
}



thanks i will play with that a bit and i am sure it will help me out
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
05-08-2007 11:19
Less speed more haste? :)

CODE
string test0 = "hello world";
string test1 = "hello %n";
string test2 = "hello %n, how are you?";
string test3 = "%n, hello there";
string test4 = "%n! %n! ...%n";

string Replace(string text, string replace, string with)
{
integer lenreplace = llStringLength(replace);
integer index = llSubStringIndex(text, replace);

while(index >= 0)
{
integer len = llStringLength(text);
if (index > 0) text = llGetSubString(text, 0, index - 1 ) + with + llGetSubString(text, index + lenreplace , len);
else text = with + llGetSubString(text, index + lenreplace , len);
index = llSubStringIndex(text, replace);
}
return text;
}

default
{
touch_start(integer total_number)
{
llOwnerSay(Replace(test0, "%n", "Pale"));
llOwnerSay(Replace(test1, "%n", "Pale"));
llOwnerSay(Replace(test2, "%n", "Pale"));
llOwnerSay(Replace(test3, "%n", "Pale"));
llOwnerSay(Replace(test4, "%n", "Pale"));
}
}
Mainly corrected a couple of typos and also guarded against the case where index returns zero (test3 and test4).

But thanks for that, I was using a similar routine but this is much tighter. :D
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-08-2007 14:01
But pale, what fun would you have if I could type?
But you are correct, that was knocked up while thinking about something else.
_____________________
I'm back......
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
05-09-2007 05:48
this is well and fine but is it going to work for reading information off of a notecard and then substuting the detected target for %n
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-09-2007 07:16
From: Bizcut Vanbrugh
this is well and fine but is it going to work for reading information off of a notecard and then substuting the detected target for %n


Ah you actually want the code to read a notecard? Sorry I read from your post that you already had that bit. try here for an example
_____________________
I'm back......
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
05-16-2007 08:02
yes i have the notecard reader already i am just trying to understand what you 2 have here so i know how to put it in the note card reader and make everything play nice =)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-16-2007 08:14
From: Bizcut Vanbrugh
yes i have the notecard reader already i am just trying to understand what you 2 have here so i know how to put it in the note card reader and make everything play nice =)


Well it will depend on exactly how you are reading and storing the data wont it?

Assuming you have stored the return from the dataserver event in a string fred and have the avatars name in a string called barney then when you want to say it just

CODE

string modifiedstring = Replace(fred, "%n", barney);
_____________________
I'm back......
Bizcut Vanbrugh
Registered User
Join date: 23 Jul 2006
Posts: 99
05-17-2007 22:52
here is the code/script i am using to read random lines from a note card

CODE

// FileReader vers. 0.31
// Description: Read a random line from a notecard from the object's inventory, upon touch.
// Author: Areyn Laurasia
// Date: 2007-04-13

// Based on examples in the LSLwiki.
string owner;
string target;
string filename = "Quotes"; // name of the notecard in the object's inventory
integer line = 0; // line number, the default first line is 0
key queryID = NULL_KEY; // id used to identify dataserver queries

default {

state_entry() {
}

touch_start(integer total_number) {
llGetNumberOfNotecardLines(filename); // the random number is based on the no. of lines in the notecard
}

dataserver(key query_id, string data) {

if (query_id != queryID) {
line = (integer) llFrand((float)data); // generate a random number
queryID = llGetNotecardLine(filename,line); // send a query to extract the line

} else {
if (data != EOF) { // note: embedded links in notecard will result in EOF
llSay(0, data); // print out a random line
}
}
}
}


i am too new to figure out how to make this read a line from the note card and input the persons name that trouched it inplace of say %t and say the current owners name inplace of say %o

example i would like this on the note card

hey %o if %t touches me again beat there ass

to come out as

object:hey Bizcut if Newgate touches me again beat there ass


but of course only if Bizcut is the current owner and Newgate is the current toucher?

but the %o and %t could be anyplace in the text on that line of the note card am i just trying to go way to far above me ?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
05-18-2007 00:19
I'd do it something like this
CODE

// FileReader vers. 0.31
// Description: Read a random line from a notecard from the object's inventory, upon touch.
// Author: Areyn Laurasia
// Date: 2007-04-13

// Based on examples in the LSLwiki.
string owner;
string target;
string filename = "Quotes"; // name of the notecard in the object's inventory
integer line = 0; // line number, the default first line is 0
key queryID = NULL_KEY; // id used to identify dataserver queries
key NumberOfLinesID = NULL_KEY; // id used to identify dataserver query for number of lines
integer TotalNumberOfLines = 0;

string Replace(string text, string replace, string with)
{
integer lenreplace = llStringLength(replace);
integer index = llSubStringIndex(text, replace);

while(index >= 0)
{
integer len = llStringLength(text);
if (index > 0) text = llGetSubString(text, 0, index - 1 ) + with + llGetSubString(text, index + lenreplace , len);
else text = with + llGetSubString(text, index + lenreplace , len);
index = llSubStringIndex(text, replace);
}
return text;
}
// -----------------------------------------------
default
{

state_entry()
{
owner = llKey2Name(llGetOwner()); // Get The owners Name
NumberOfLinesID = llGetNumberOfNotecardLines(filename);// the random number is based on the no. of lines in the notecard
}

touch_start(integer total_number)
{
target = llKey2Name(llDetectedKey(0)); // get the toucher's name
line = (integer) llFrand((float)TotalNumberOfLines); // generate a random number
queryID = llGetNotecardLine(filename,line); // send a query to extract the line
}

dataserver(key query_id, string data)
{
if(query_id == NumberOfLinesID)
{
TotalNumberOfLines = (integer)data;
NumberOfLinesID = NULL_KEY;
}
else if (query_id == queryID)
{
queryID = NULL_KEY;
string text = Replace(data,"%o", owner);
text = Replace(text,"%t", target);
llSay(0,text);
}
}

changed(integer change)
{
if((change & CHANGED_OWNER) | (change & CHANGED_INVENTORY)) llResetScript();
}
}
_____________________
I'm back......