Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

notecards and dataserver

Azrael Baphomet
Registered User
Join date: 13 Sep 2005
Posts: 93
09-30-2005 08:13
Hi...I'm trying to write a script that can take commands I utter via chat and compare them to the various lines in a notecard. However, I'm running into some difficulty actually getting dataserver to perform as (I thought it was) described in the wiki.

Here's my code:


CODE
 string gName="notecard";
integer gLine=0;
string data;
key gQueryID;

default{
state_entry()
{
Handle=llListen( 0, "", NULL_KEY, "" );
}

touch_start(integer total_number)
{
llSay(0,"Good Morning, Azrael");
gLine=0;
}

listen(integer channel, string name, key id, string message)
{
gQueryID=llGetNotecardLine(gName,gLine); //get line of notecard
}

dataserver(key query_id,string data)
{
if(data!=EOF & gQueryID==query_id )
{

//data is processed here. Code not included.
gLine++;
gQueryID=llGetNotecardLine(gName,gLine);
}
}
}


The trouble appears to be with the line "if(data!=EOF & gQueryID==query_id )"
gQueryID never seems to equal query_id. On first execution of listen(), shouldn't gQueryID be identical with query_id? Why would it not be? Dataserver() is called....
if I put an llSay anywhere within dataserver I can get it to output each line of the notecard.
but the conditional is never fulfilled.

Is there a better way (more functional, more compact) to have written this?
I'd appreciate any and all assistance. I'm still new to LSL, and I learn new scripting languages with something less than alacrity. Thanks!
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-30-2005 08:33
Awww ! AWWWWWWWW ! Asset server BURNING !

Please don't use this script. Pretty please with sugar and a cherry on top. Don't. It's not even functional, since you don't pass whatever the script hears to your comparison code.



Here's a significantly better (as in faster and easier for the server) method: when the script starts, have it read the notecard and store the commands into a list.

Then when it hears something from you have it compare what you said with the list's contents with a single call to llListFindList()

Also: please don't make it listen for EVERYTHING EVERYONE says on the PUBLIC CHANNEL. This is BAD. Bad as in, planting nails in your hand, with an hydraulic press. Make it listen to your key only instead, and ideally on another channel instead of 0.

Another method worth trying: have the script read the notecard upon starting, and launch a new listen for each command, listening SPECIFICALLY for this command from you (using an llListen(0, "", llGetOwner(), the_command);
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Azrael Baphomet
Registered User
Join date: 13 Sep 2005
Posts: 93
09-30-2005 08:39
From: Jesrad Seraph
Awww ! AWWWWWWWW ! Asset server BURNING !




Here's a significantly better (as in faster and easier for the server) method: when the script starts, have it read the notecard and store the commands into a list.

Then when it hears something from you have it compare what you said with the list's contents with a single call to llListFindList()



The notecard is going to be fairly long. Lists can only consist of 72 elements, no? The card will likely have more lines then this, when all the patterns I'm interested in are included.

and is this code from the wiki also bad (as in not functional)?:

CODE

string gName = "Testnotecard"; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries

default {
state_entry() {
gQueryID = llGetNotecardLine(gName, gLine); // request first line
gLine++; // increase line count
}

dataserver(key query_id, string data) {
if (query_id == gQueryID) {
if (data != EOF) { // not at the end of the notecard
llSay(0, data); // output the line
gQueryID = llGetNotecardLine(gName, gLine); // request next line
gLine++; // increase line count
}
}
}

}
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-30-2005 08:46
This code is perfectly fine, it reads the notecard at script start. That's where you want to work from to make your command parser :)

And I've got lists well over 200 in some of my scripts, I don't think there is a hard limit to the number of elements you can have in them, apart from the 16K memory limit (LSL only limits how many elements you can put in a list at definition time, if you want a LARGE list in your script just add the elements to it one big chunk after the other in the state_entry() event).
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Azrael Baphomet
Registered User
Join date: 13 Sep 2005
Posts: 93
09-30-2005 08:59
Gotcha...I'll give it a whirl. And I promise I won't use the skeleton code I posted up top. ;)
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
09-30-2005 09:55
And to answer your question, the reason it didn't work is because:

CODE
if(data!=EOF & gQueryID==query_id )


Should be:

CODE
if(data!=EOF && gQueryID==query_id )
Azrael Baphomet
Registered User
Join date: 13 Sep 2005
Posts: 93
09-30-2005 10:29
From: Ziggy Puff
And to answer your question, the reason it didn't work is because:

CODE
if(data!=EOF & gQueryID==query_id )


Should be:

CODE
if(data!=EOF && gQueryID==query_id )


I've been programming MATLAB too long.
Chandra Page
Build! Code. Sleep?
Join date: 7 Oct 2004
Posts: 360
09-30-2005 10:58
From: Azrael Baphomet
The notecard is going to be fairly long. Lists can only consist of 72 elements, no? The card will likely have more lines then this, when all the patterns I'm interested in are included.


The 72-element limit you're thinking of is the limit on how many items you may use when defining a list in LSL. The compiler can only assemble 72 pre-defined list elements at a time. For example, assume you've got something like this at the beginning of your code:

CODE

list hugeList = ["first list item",
"second list item",
"third list item",
...
"last list item"];


Such a definition may contain, at most, 72 elements. However, the list data type may contain as many elements as you can shove into available memory (16 kilobytes). If you're reading in data from a notecard, the list can be quite large, assuming that the invididual elements of the list aren't all huge strings that will quickly chew up the memory available to the script.
_____________________
Come visit the In Effect main store and café
Drawbridge (160, 81)
Particle effects, fashion, accessories, and coffee!
On the Web at SL Exchange and SL Boutique