LlDetermineType

From Second Life Wiki
Jump to: navigation, search
Emblem-important-yellow.png LSL Feature Request
The described function does not exist. This article is a feature request.

Summary

Function: integer llDetermineType( string source, integer start, integer end );
REQUEST Function ID
0.0 Forced Delay
0.0 Energy

Returns an integer to represent the type of the part of the string.

• string source The string that you are determining the type of a part of.
• integer start The start point in the string of what you are determining.
• integer end The end point in the string of what you are determining.

start & end do not support negative indexes.

Type Description
TYPE_INTEGER 1 integer
TYPE_FLOAT 2 float
TYPE_STRING 3 string
TYPE_KEY 4 key
TYPE_VECTOR 5 vector
TYPE_ROTATION 6 rotation
TYPE_INVALID 0 none

Caveats

  • If either start or end are out of bounds the script continues to execute without an error message.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> default {

   state_entry()
   {
       llListen(0,"",llGetOwner(),"");
   }
   listen(integer chan, string name, key id, string msg)
   {
       if(llDetermineType(msg,0,-1) == TYPE_INTEGER)
       {
           integer new_number = (integer)msg;
           vector also = <new_number,new_number*8,new_number/3>;
           llOwnerSay("The number you just said was "+(string)new_number+" and put in a vector, it is "+also+".");
       }
   }    

}

</lsl>

Useful Snippets

<lsl> // Released into the public domain by Adam Wozniak and Doran Zemlja in 2010 // Free for anyone to use for any purpose they like. // // LSL implementation of llDetermineType

integer dzDetermineType(string s) {

  integer n;
  // is it an integer?
  if ((string)((integer) s) == s) {
     return TYPE_INTEGER;
  }
  // is it a rotation or a vector?
  list parsed = llParseString2List(s, [","], []);
  if (llSubStringIndex(s, "<") == 0) {
     // is it a vector?
     if (llGetListLength(parsed) == 3) {
        return TYPE_VECTOR;
     }
     // is it a rotation?
     if (llGetListLength(parsed) == 4) {
        return TYPE_ROTATION;
     }
  }
  // is it a key?
  parsed = llParseString2List(s, ["-"], []);
  if (llStringLength(s) == 36 && llGetListLength(parsed) == 5) {
     return TYPE_KEY;
  }
  // is it a float?
  n = 0;
  if (llSubStringIndex(s, "-") == 0) {
     n = 1;
  }
  parsed = llParseStringKeepNulls(llGetSubString(s, n, -1), ["."], []);
  if (llGetListLength(parsed) == 2) {
     string i = "1" + llList2String(parsed, 0);
     string f = "1" + llList2String(parsed, 1);
     if (((string)((integer) i) == i) && ((string)((integer) f) == f)) {
        return TYPE_FLOAT;
     }
  }
  // must be a string then
  return TYPE_STRING;

} </lsl>

Notes

Should make it easier for scripters to determine the types of parts of strings in order to get accurate results as opposed to manually deriving them from the string. Could anyone delete the unnecessary parts to this page? This is my first time editing and I can't find it :P

Deep Notes

Search JIRA for related Issues

Signature

//function integer llDetermineType( string source, integer start, integer end );

Comments

The trouble is, that when it comes to floats it's hard to tell them from integers if the decimal has been stripped. Or strings from keys... or strings that look like any of the other types. You can guess but you can't be sure; if you are building a function on top of logic that isn't perfect then you end up with something that isn't all that useful. -- Strife (talk </div></div>