LSL feature request. The described function does not exist. This article is a feature request.
integer llDetermineType( string source, integer start, integer end );
Forced delay: 0.0 seconds. Energy: 0.0.
start & end do not support negative indexes.
Returns an integer to represent the type of the part of the string.
| 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 |
<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>
<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>
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
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