Jump to content

SubStringIndex strange return value?


phaedra Exonar
 Share

You are about to reply to a thread that has been inactive for 4265 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've been using GetSubString to read config variables from a note card name, I do this to save run time vs. using a dataserver to read the note card.  This has been working fine, but now I need to add a second vector.  The first vector worked fine because it's at the end incase the number of spaces it takes up in the string changed. 

To add a second vector, I need to add a SubStringIndex to deal with the possible changing length of the 2 vectors.  I've used the same variable to create the SubStrinIndex in other scripts and it worked fine, but here I'm getting a return value of 23 form ":" and the index shows up in the next variables, and fails to return the last vector. 

I don't know if this is an issue with getting the string from a note card name or if I'm missing something setting up or using the SubStringIndex?

 

default
{
    state_entry()
    {
        string gNoteName=llGetInventoryName(INVENTORY_NOTECARD, 0 );
        integer vectorMark = llSubStringIndex(gNoteName,":");
        vector startRot =(vector)llGetSubString(gNoteName, 8, (vectorMark -1));
        vector endPos =(vector)llGetSubString(gNoteName, (vectorMark +1), -1);
        llOwnerSay("vectorMark= " + (string)vectorMark);
        llOwnerSay("startRot= " + (string)vectorMark + (string)startRot);
        llOwnerSay("endPos= " + (string)vectorMark + (string)endPos);
    }
}
/*
note card name:
    1,1,2,2,<3.0, 3.0, 3.0>:<0.4 ,0.4, 0.4>

return values:
    vectorMark= 23
    startRot= 23<3.00000, 3.00000, 3.00000>
    endPos= 23<0.40000, 0.40000, 0.40000>

 

 

 

 

 

Link to comment
Share on other sites

Thanks, now  gives me the correct value of the second vector but it's still got the 23 added, here's the new return values.  I fixed the original post too.

[01:29] Object: vectorMark= 23
[01:29] Object: startRot= 23<3.00000, 3.00000, 3.00000>
[01:29] Object: endPos= 23<0.40000, 0.40000, 0.40000>

Link to comment
Share on other sites

That's just the debug function I took it out of the rest of the script to make testing quicker, I think the problem is where I'm testing it with OwnerSay it's seeing the index as a string, normally script for the last vector look like this

vector endPos =(vector)llGetSubString(gNoteName, (vectorMark +1), -1);
llUpdateSitTarget(endPos, ZERO_ROTATION);

originally with out the index it looked like this, and works.

default
{
    state_entry()
    {
        string gNoteName=llGetInventoryName(INVENTORY_NOTECARD, 0 );
        vector endPos=(vector)llGetSubString(gNoteName, 8, -1);
        llOwnerSay("endPos= " + (string)endPos);
    }
}

______________________________________________________________________________________________

it works fine until I add the index, here's the index variables I used before, the full script can be found here

http://forums-archive.secondlife.com/54/1a/195124/1.html

 

 email(string time, string address, string subject, string body, integer remaining)
    {
        llOwnerSay("Received Request...");
        if (InUse == FALSE)
        {
            InUse = TRUE;
            llSetText("In Use...",<1,1,1>,1.0);
            string message = llDeleteSubString(body, 0, llSubStringIndex(body, "\n\n") + 1);
            integer itemMark = llSubStringIndex(message,":");
            integer verMark = llSubStringIndex(message,"|");
            item = llGetSubString(message,0,(itemMark - 1));
            version = llGetSubString(message,(itemMark + 1),(verMark - 1));
            user = (key)llGetSubString(message,(verMark + 1), -1);
            llOwnerSay("Item: " + item);
            llOwnerSay("Version: " + version);
            llOwnerSay("User: " + llKey2Name(user));
            lineCurrent = 0;
            locateID = llGetNotecardLine(cardName,0);
        }
    }

__________________________________________________________________________________________________
What I don't get is way this returns: 23  

integer vectorMark = llSubStringIndex(gNoteName,":");
llOwnerSay("vectorMark= " + (string)vectorMark);

I can see why it would add the index to the string here, but I would expect it to be : not 23, but the example above from the script with the link all so doesn't add the index to the vector like this does.

 

Link to comment
Share on other sites

I don't understand the question at all.  I'm sorry.   

I've just tried this:

default{    state_entry()    {        integer vectorMark;        string marker = ":";        string gNoteName="1,1,2,2,<3.0, 3.0, 3.0>:<0.4 ,0.4, 0.4>" ;        gNoteName=llStringTrim(gNoteName,STRING_TRIM);//safety precaution        vectorMark = llSubStringIndex(gNoteName,marker);        llOwnerSay("vectorMark is "+(string)vectorMark);        vector startRot = (vector)llGetSubString(gNoteName, 8, (vectorMark -1));        llOwnerSay("startRot is "+(string)startRot);        vector endPos =(vector)llGetSubString(gNoteName, (vectorMark +1), -1);        llOwnerSay("endPos is "+(string)endPos);    }}

 As you'd expect, it says

[05:14] Object: vectorMark is 23[05:14] Object: startRot is <3.00000, 3.00000, 3.00000>[05:14] Object: endPos is <0.00000, 0.00000, 0.00000>

 What's your's saying and what do you want it to say?

ETA -- yes, I do see the problem.  Silly me.  endPos should not be ZERO_VECTOR.  Hmm.

This is so strange.  I fixed the problem by removing the spaces between the elements of the second vector;  that is, it can understand <0.4,0.4,0.4> but not <0.4, 0.4, 0.4>.   But why it should have problems with the second vector and not the first, I don't know.

default{    state_entry()    {        integer vectorMark;        string marker = ":";        string gNoteName="1,1,2,2,<3.0, 3.0, 3.0>:<0.4,0.4,0.4>" ;        gNoteName=llStringTrim(gNoteName,STRING_TRIM);//safety precaution        vectorMark = llSubStringIndex(gNoteName,marker);        llOwnerSay("vectorMark is "+(string)vectorMark);        vector startRot = (vector)llGetSubString(gNoteName, 8, (vectorMark -1));        llOwnerSay("startRot is "+(string)startRot);       // string s = llGetSubString(gNoteName, (vectorMark +1), -1);      //  llOwnerSay("s is "+s);        vector endPos =(vector)llStringTrim( llGetSubString(gNoteName, (vectorMark +1), -1),STRING_TRIM);        llOwnerSay("endPos is "+(string)endPos);    }}

 gives 

[08:59] Object: vectorMark is 23[08:59] Object: startRot is <3.00000, 3.00000, 3.00000>[08:59] Object: s is <0.4,0.4,0.4>[08:59] Object: endPos is <0.40000, 0.40000, 0.40000>

 

Link to comment
Share on other sites

The second vector had a bogus character in it.  It doesn't mind spaces in <0.4, 0.4, 0.4> but it doesn't like the bogus character.

BTW, try this ...

default{    state_entry()    {        string gNoteName="1,1,2,2,<3.0, 3.0, 3.0>:<0.4, 0.4, 0.4>" ;        list temp = llParseString2List(gNoteName,[",<",":"],[]);        vector startRot = (vector)("<" +llList2String(temp,1));        llOwnerSay("startRot is "+(string)startRot);        vector endPos = (vector)llList2String(temp,2);        llOwnerSay("endPos is "+(string)endPos);    }}

 You don't have to mess with vectorMark at all.

Link to comment
Share on other sites

Thanks Innula, I think my problem had been a spacing error in the notecard name, is that what the StringTrim you add protect against?   I had all so add the markers to the debug in places I didn't need it, I think originally I had all the debug in one string and forgot to remove the extra marker form the others. 
The part that really through me off  is why does this return 23? Apparently it doesn't matter, but distracted me from seeing the real problems.

        string marker = ":";        string gNoteName="1,1,2,2,<3.0, 3.0, 3.0>:<0.4 ,0.4, 0.4>" ;        gNoteName=llStringTrim(gNoteName,STRING_TRIM);//safety precaution        vectorMark = llSubStringIndex(gNoteName,marker);        llOwnerSay("vectorMark is "+(string)vectorMark);

 

 

Link to comment
Share on other sites


phaedra Exonar wrote:

Thanks Innula, I think my problem had been a spacing error in the notecard name, is that what the StringTrim you add protect against?   I had all so add the markers to the debug in places I didn't need it, I think originally I had all the debug in one string and forgot to remove the extra marker form the others. 

The part that really through me off  is why does this return 23? Apparently it doesn't matter, but distracted me from seeing the real problems.
        string marker = ":";        string gNoteName="1,1,2,2,<3.0, 3.0, 3.0>:<0.4 ,0.4, 0.4>" ;        gNoteName=llStringTrim(gNoteName,STRING_TRIM);//safety precaution        vectorMark = llSubStringIndex(gNoteName,marker);        llOwnerSay("vectorMark is "+(string)vectorMark);

 

 

I'd put in llStringTrim in case there were extra characters at the start or the end of the notecard name.  I'm not sure if it makes any difference in this case, but it's a precaution I always take when reading notecards.    The problem, though, was the one Rolig spotted.

I don't understand what you're asking about llSubStringIndex.  In that example, ":" is the 23rd character (including spaces and punctuation marks, starting counting at 0 rather than one) in the string.   So that's why llSubStringIndex returns 23.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4265 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...