Jump to content

Typecasting string to vector fails


revochen Mayne
 Share

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

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

Recommended Posts

Greetings!

 

I'm trying to set a prims light by a config notecard which contains mulitple lines for the light parameters. One of the lines sais:

color = <1,0,0>

 The prim is containing a script which will start reading the config notecard on touch and sets the light parameters when the notecard reading process finished (EOF). But i figured that typecasting a string to vector doesn't work as expected somehow although i know it has to, did it so often in the past. Why it's not working now? óò

Thats the code out of the dataserver event:

(The original code contains further else if statements for any light parameter)

    dataserver(key request, string data)
    {
        if(request==notecard_request)
        {
            if(data!=EOF)
            {
                
                list data_split = llParseString2List(data,["="],[]);
                string left = llToLower( llStringTrim(llList2String(data_split,0),STRING_TRIM));
                string right = llStringTrim(llList2String(data_split,1),STRING_TRIM);
                
                if(left=="color")
                {
                    color = (vector)right;
                    llOwnerSay((string)color+" "+right); // results in <0,0,0> <1,0,0>
                }
                
                ++notecard_line;
                notecard_request = llGetNotecardLine(notecard_name,notecard_line);
            }
            else
            {
                llSetPrimitiveParams([PRIM_POINT_LIGHT,1,color,10,1,1]);
            }
        } 
}

 

I was also trying several options like having the vector elements as floats, with and without spaces between but it seems to be the typecast as the "right" variable does get the proper vector.

 

Also

color = llList2Vector(data_split,1);

and

color = (vector)llList2String(data_split,1);

 doesnt work!

 

Any idea whats wrong?

 

 

Link to comment
Share on other sites

llList2Vector does NOT work - it does NOT typecast.

(vector)right   or   (vector)llList2String...    DO work.


In the notecard the line is:

color=<1,0,0>

Don't miss the <>

Besides of that I don't see a possibility for an error. The global variable color is a vector or it will not compile. Make a new notecard and test again.

 

Link to comment
Share on other sites

Always best to use fresh configuration notecards and scripts. Sometimes legacies remain even in objects. Deleting some scripts in an object does not allway full remove it. Hovering text scripts are the worst offender for that.

ADDED: I allways include this line in readers. 

if(data != "")//ignore empty spaces

Link to comment
Share on other sites

In fact llList2Vector() does work but it works reliably only if the item was originally stored in the list as a vector. If it were originally stored as a string (like in the case at hand from config card) more often than not it does not work, though on some occasions does.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3852 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...