Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Card reader problem

Mod Faulkner
Registered User
Join date: 11 Oct 2005
Posts: 187
04-21-2006 16:31
Subjecting myself to public ridicule once more I need help: I have a card reader that reads a line that contains two vectors; one for offset and the other for a eul used in a rotation calculation
The card is formatted with both vectors on the same line separated by a “;” as follows:
<0.7,0.3,0>;<0,0,235>

skipping the globals the code is as follows:
CODE

default
{
state_entry()
{
posList = [];
rotList = [];
gQueryID = llGetNotecardLine(gName, gLine); // request first line
}

dataserver(key query_id, string data)
{
if (query_id == gQueryID)
{
if (data != EOF)
{ // not at the end of the notecard
integer parse = llSubStringIndex(data, ";");
integer length = llStringLength(data);
if(llGetSubString(data,0,0) != "<")
if(llGetSubString(data,parse - 1,parse - 1) != ">")
if(llGetSubString(data,parse +1 ,parse +1) != "<")
if(llGetSubString(data,length - 1,length) != ">")
posList = posList + llGetSubString(data,0, parse - 1);
rotList = rotList + llGetSubString(data, parse + 1, length);
++gLine; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request line
}
}
}

(Note the “if” functions are broken out rather that combined to look for things might be going wrong)

The results are that when called using:

integer index = i;
offset = (vector) llList2String(posList, index);
eul = (vector) llList2String(rotList, index);

the eul vector that is retrieved is what is on the card, but the offset vector comes out as <0,0,0> every time. Call me dumb but tell me what is wrong.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
04-21-2006 17:09
I'm too tired to work your script out, sorry.

But why not:

list temp=llParseString2List(data, [";"], []);
vector pos=(vector)llList2String(temp, 0);
vector rot=(vector)llList2String(temp, 1);

?
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-21-2006 17:17
if(llGetSubString(data,length - 1,length) != ">";) should be
if(llGetSubString(data,length,length) != ">";)

...but as the rotList ='s line is unconditional (which I think is also a mistake) it gets retrieved successfully.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-21-2006 17:21
The if's will nest, but since there's no braces, only one line following the last if check will be included in the if check. So your position line is inside the if, your rotation line isn't. Here's what your code looks like with the braces added:

CODE

if(llGetSubString(data,0,0) != "<")
{
if(llGetSubString(data,parse - 1,parse - 1) != ">")
{
if(llGetSubString(data,parse +1 ,parse +1) != "<")
{
if(llGetSubString(data,length - 1,length) != ">")
{
posList = posList + llGetSubString(data,0, parse - 1);
}
}
}
}

rotList = rotList + llGetSubString(data, parse + 1, length);


Suggestion - always use braces with if checks, it makes it easier to catch errors like these. And of course, like everyone else said, why not use the built in string-to-list functions?

Of course, someone beat me to it again :)