Typically, the problem is in how the variable is changed when you typecast. If you look into some of my newer scripts, for example, you'll see me jumping through a lot of hoops with variable types. I didn't have to for most of it, but it was to be doublesure the script works in the future.
Simply put, though, when you want to typecast through a list, and vice versa (example: using lists from llParseString2List), you need to be wary of interchangability of variable types, but more importantly, how to get around it.
For example, llParseString2List returns a list that, amazingly, is full of strings. To get around this for
all variable types, I do
(variable type)llList2String(listname,num);However, you need not do it that way. Here are some examples of how variables will work, interchangably, with typecasting before, and after, a list:
Edit: For each of the tests, I commented out the other tests. This is why you see duplicate variable declarations and references to slot 0 in the list.// Tested all of this in world. Note variable names are photocopied,
// so you would not get this code to compile verbatim.
list test = [];
// Works:
test += (vector)<0,0,0>;
llSay(0,llList2String(test,0));
// Does not work:
vector testit = <0,0,0>;
test += "<1,1,1>";
testit = llList2Vector(test,0);
llSay(0,(string)testit);
// Works:
vector testit = <0,0,0>;
test += "<1,1,1>";
testit = (vector)llList2String(test,0);
llSay(0,(string)testit);
// Works:
integer testit = 0;
test += "5";
testit = llList2Integer(test,0);
llSay(0,(string)testit);
// Works:
integer testit = 0;
test += "5.0";
testit = (integer)llList2Float(test,0);
llSay(0,(string)testit);
// Works:
string testit = "This is a key";
test += testit;
key so_is_this = "This is a key";
llSay(0,(string)llListFindList(test,(list)so_is_this));
// Works:
string testit = "This is a key";
test += (list)testit;
key so_is_this = "This is a key";
llSay(0,(string)llListFindList(test,(list)so_is_this));
// Does Not Work:
string testit = "12345";
test += testit;
llSay(0,(string)llListFindList(test,(list)12345));
// Does Not Work:
integer testit = 12345;
test += testit;
llSay(0,(string)llListFindList(test,(list)12345.0));
// Works:
integer testit = 12345;
test += testit;
llSay(0,(string)llListFindList(test,(list)((integer)12345.0)));
// Works:
rotation testit = <0,0,0,0>;
test += "<1,1,1,1>";
testit = (rotation)llList2String(test,0);
llSay(0,(string)testit);
// Does not work:
rotation testit = <1,1,1,0>;
test += "<0,0,0,2>";
testit = llList2Rot(test,0);
llSay(0,(string)testit);
It's of note that
vectors and
rotations do not typecast properly out of a list via llList2(Type) if stored as a string. However, as a general rule, everything else seems to.
Also of note, strings and keys work interchangably with llListFindList, and for that matter, so does typecasting at each end. This makes sense.
Typecasting directly from a list to a string via llList2String also appears to be a golden medium for variables, but that may easily change.
llListFindList, however, does not work with types that are radically different, like strings and integers.
Anyone want me to Wiki this?