Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

chat replies from a notecard

MacDracor Jun
Registered User
Join date: 1 Jun 2007
Posts: 11
07-30-2008 14:51
I am looking for a way to script chat responses from a notecard instead of

if (message == "hello";)
{
llSay(0, "Hello! How are you?";);
}

So that the notecard could be updated instead of editing the script when I want to change the responses.

I am not too good at reading notecards. Was hoping for a notecard where each line could be formatted like

hello ; Hello! How are you?

and the script would pull the keyword and the response from it. Hoping to be able to have a long list in the notecard.
I hope I am making sense here. LOL
Jenn Yoshikawa
Registered User
Join date: 14 Nov 2007
Posts: 91
Note card reader
07-30-2008 15:20
key readKey;
string config = "Settings";
integer listenQueryID;
integer count;
integer lineCount;
string msg;

default
{
state_entry()
{
readKey = llGetNotecardLine(config, lineCount);
}
dataserver(key requested, string data)
{
string stringData;
if (requested == readKey)
{
if (data != EOF)
{
if ((llSubStringIndex(data, "//";) != 0) && (data != "";) && (data != " ";))
{
stringData = (string)data;
if (count == 0)
{
msg = stringData;
}
count += 1;
}
lineCount += 1;
readKey = llGetNotecardLine(config, lineCount);
}
}
}
}
MacDracor Jun
Registered User
Join date: 1 Jun 2007
Posts: 11
Wow, that was fast!
07-30-2008 15:26
Thank you for your quick response. Much of this is over my head. But, it does not seem to include what I am looking for, and seeing as how I do not really understand dataserver, I don't wanto muck with it too much.
The script I made sets up a listener on channel 0. It has an else if list of words that it will reply to.
like, if message == "hello" llSay (0, "hello!";) if else message == "how are you?" llSay"Fine, thanks."
Etc. I am looking for a way to streamline it and use a notecard to contain the list of words it listens for, and what the llSay responses will be. Does that make sense?
Booradley Shikami
Registered User
Join date: 13 Jan 2008
Posts: 3
07-30-2008 16:02
Hi there, i wrote up and tested a quick no frills example of this:

Here is the script (remove the PHP tags if you can see them)

CODE

// Setup
string notecard_name = "Your Notecard Name";
integer notecard_line = 0;
key query_id;
list message_list = [];
list response_list = [];

default {
state_entry() {
// Create listener
llListen(0, "", NULL_KEY, "");
// Read notecard
query_id = llGetNotecardLine(notecard_name, notecard_line);
}
dataserver(key q_id, string data) {
list temp;
if (q_id == query_id) {
if (data != EOF) {
if ( llGetSubString(data, 0, 0) != "#" && llStringTrim(data, STRING_TRIM) != "" ) {
temp = llParseString2List(data, ["="], []);
message_list += [llStringTrim(llToLower(llList2String(temp, 0)), STRING_TRIM)];
response_list += [llStringTrim(llList2String(temp, 1), STRING_TRIM)];
}
// Get next line
++notecard_line;
query_id = llGetNotecardLine(notecard_name, notecard_line);
}
}
}
listen(integer channel, string name, key id, string message) {
// Check message_list for message and respond with appropriate response if found
integer message_index = llListFindList(message_list, [message]);
if(message_index != -1) {
llSay(0, llList2String(response_list, message_index));
}
}
changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript();
}
}
}


And here is the format of the notecard that you need to include in your object:

(The first part of each line is the message it listens for, and the part after the = sign is what it responds with) Name this notecard whatever you want to, but be sure to update the variable at the top of the script accordingly.

CODE

test 1 = test response 1
test 2 = test response 2


*EDIT - Good call Jenn, I added that change in.
Jenn Yoshikawa
Registered User
Join date: 14 Nov 2007
Posts: 91
re
07-30-2008 16:08
nah just add changed command have it do it by its self lol
MacDracor Jun
Registered User
Join date: 1 Jun 2007
Posts: 11
Whooo hooo!
07-30-2008 16:17
Thank you so much!