Neverworld Grid

You are not logged in. Would you like to login or register?

6/25/2019 6:37 pm  #1

Check if input is a VECTOR - ideal to include in your preprocessor

Method to check if a given string can be typecast to a VECTOR. Use independently or add the method to your LSL preprocessor folder and add an include statement to your script. 

#include "chkisvec.lsl"
integer isVec = ChkIsVec (string inputString)

integer ChkIsVec (string inputString)
{ // returns a true if supplied string is a vector and false if it is not
    integer isVec;
    vector chkVec = (vector)inputString;
    string startProcess = llStringTrim ((inputString), STRING_TRIM);
    integer startIndex = (llSubStringIndex(startProcess, "<")+1);
    integer endIndex = (llSubStringIndex(startProcess, ">")-1);
    startProcess = llGetSubString(startProcess, startIndex, endIndex); //removes the first and the last characters ("<" and ">")
    list stringParts = llCSV2List(startProcess); //turn the remaining list elements into a list
    string strX =  llStringTrim( (llList2String(stringParts,0)), STRING_TRIM); // new string for x with whitespace removed
    string strY =  llStringTrim( (llList2String(stringParts,1)), STRING_TRIM); // new string for y with whitespace removed
    string strZ =  llStringTrim( (llList2String(stringParts,2)), STRING_TRIM); // new string for z with whitespace removed
    float fltX = (float) strX;
    float fltY = (float) strY;
    float fltZ = (float) strZ;
    vector reformedVec = <fltX, fltY, fltZ>;
    if (inputString == "") isVec  = FALSE;
    else if ((chkVec - reformedVec) == <0,0,0>) isVec = TRUE;
    else isVec  = FALSE;
    return isVec;
}//close chk is a vector 

Last edited by sara (6/26/2019 3:44 am)


Board footera


Powered by Boardhost. Create a Free Forum