Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Error reading from notecard

Over Sleeper
I Dream in LSL
Join date: 12 Jan 2006
Posts: 141
03-16-2006 05:53
I am using this script to use a command to switch textures from a notecard. The problem is that if I say a command that is not even in the notecard, it switched to the first texture or gives a stack heap collission error.

Can anyone see what might be wrong with it?

CODE
string commandNotecard = "MyNotecard"; 
integer listenChan = 1; // channel to listen to
list TheTexture = [];
list TheCommand = [];
integer lineNum = 0;
key requestId; //The dataserver request id for the current line
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setCustomTexture");
}
default
{
state_entry()
{
llListen(listenChan,"","","");
requestId = llGetNotecardLine(commandNotecard, lineNum);
}

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

dataserver(key id, string data)
{
if ( ( id == requestId ) && ( data != EOF ) ) //Not EOF and right data
{
list parsed = llParseString2List( data, [","], [] );
if ( llGetListLength( parsed ) != 2 ) //Uh-oh, invalid command format
{
llOwnerSay("Received mutilated command from notecard:\"" +
data + "\" line number: " + (string)lineNum );
}
else
{
TheTexture += llList2List( parsed, 0, 0 );
TheCommand += llList2List( parsed, 1, 1 );
}
lineNum++;
requestId = llGetNotecardLine(commandNotecard, lineNum);
}
}

listen(integer channel, string name, key id, string message)
{
integer index = llListFindList( TheCommand, [llToLower(message)] );
if ( index != -1 )
llOwnerSay( llList2String( TheTexture, index ) );
setLinkTexture(LINK_SET, llList2String(TheTexture,index), ALL_SIDES);
llResetScript();
}
}
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
03-16-2006 06:10
Indentation can elucidate:
CODE
string commandNotecard = "MyNotecard"; 
integer listenChan = 1; // channel to listen to
list TheTexture = [];
list TheCommand = [];
integer lineNum = 0;
key requestId; //The dataserver request id for the current line
setLinkTexture(integer linkNumber, string textureKey, integer side) {
llMessageLinked(linkNumber, side, textureKey, "setCustomTexture");
}
default
{
state_entry()
{
llListen(listenChan,"","","");
requestId = llGetNotecardLine(commandNotecard, lineNum);
}

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

dataserver(key id, string data)
{
if ( ( id == requestId ) && ( data != EOF ) ) //Not EOF and right data
{
list parsed = llParseString2List( data, [","], [] );
if ( llGetListLength( parsed ) != 2 ) //Uh-oh, invalid command format
{
llOwnerSay("Received mutilated command from notecard:\"" +
data + "\" line number: " + (string)lineNum );
}
else
{
TheTexture += llList2List( parsed, 0, 0 );
TheCommand += llList2List( parsed, 1, 1 );
}
lineNum++;
requestId = llGetNotecardLine(commandNotecard, lineNum);
}
}

listen(integer channel, string name, key id, string message)
{
integer index = llListFindList( TheCommand, [llToLower(message)] );
if ( index != -1 )
llOwnerSay( llList2String( TheTexture, index ) );
setLinkTexture(LINK_SET, llList2String(TheTexture,index), ALL_SIDES);
llResetScript();
}
}


Your listen event should go more like:
CODE
    listen(integer channel, string name, key id, string message) 
{
integer index = llListFindList( TheCommand, [llToLower(message)] );
if ( index != -1 ) {
llOwnerSay( llList2String( TheTexture, index ) );
setLinkTexture(LINK_SET, llList2String(TheTexture,index), ALL_SIDES);
llResetScript();
} else {
llOwnerSay( "Not found: " + message );
}
}
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
03-16-2006 11:26
I don't think that llResetScript should be in the listen.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey