Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Casting Variables and Error Handling

Rock Ryder
Registered User
Join date: 6 Oct 2006
Posts: 384
09-23-2007 01:47
Hi guys,

I can find in the wiki all the information on the different kinds of errors that can occur in a script in either compile time or run time, but I cannot find much on error handling, error trapping etc. If there is such a section can someone point me to it?

The specific error I want to trap right now is a possible casting error.

The script is listening on channel 55 for a vector from the user and asks the user to type a vector in chat using the following format

/55<102,38,26>

As this enters the script as a string I am converting it to a vector using coords = (vector)msg, where coords is declared vector variable and msg is the string variable produced by the listen event.

The error I want to trap is where the user types in values that are not numbers, or numbers that are out of range, such as:

/55<34, %6, #7>
/55<22,304,1072>

So what is the lsl equivalent of following the casting with On Error ... ?

TIA

Rock
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
09-23-2007 05:18
From: Rock Ryder
The error I want to trap is where the user types in values that are not numbers, or numbers that are out of range, such as:

/55<34, %6, #7>
/55<22,304,1072>
I don't believe LSL has any native error handling as you describe it.

Without checking, I'm going to guess that your first example, when cast to a vector, would either result in ZERO_VECTOR ( <0,0,0> ), or possibly only the components containing invalid characters would be zeroed ( <34,0,0> ). About the only way to rule out such a circumstance would be to manually verify that the string in question begins with <, ends with >, has two commas and no characters other than 0-9, decimal, dash, and space. For example, iterate through each character of the string, and test against a list containing valid characters. If invalid, delete it.

As for the out-of-bounds check, that too would have to be done manually, assuming the test for a valid vector string was passed.
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
09-23-2007 13:31
Deanna is right I'm afraid, LSL has no error handling what so ever.
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
09-23-2007 14:19
Deanna is also right about the casting. If you try to cast a non-numeric to a vector, it will come out zero.

If it's data coming from chat, I'd recommend just having the user forgo the brackets and simply use commas. Then parse the result with the parse functions.

I don't know that I'd even bother with checking for bad data, but simply out of bounds data and zero's. It's generally not worth it, imo, to scan the string and remove invalid characters. At the most, if it detects anything invalid, just kick the entire thing back to the user and make them retype it.

This is a bit of what deanna was describing, but it doesn't test or delete individual characters. It merely checks that there are no non-numerics.

list p = llParseString2List(string, [",", "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", " ", "."], []);
integer i = llGetListLength(p);
if (p > 0) {
llSay(0, "you entered a non-numeric character. Please retry.";);
}
Anthony Hocken
Registered User
Join date: 16 Apr 2006
Posts: 121
09-23-2007 19:37
I've seen an example on the wiki for checking if a string represents a valid vector.

Here it is. See the "Verifying a vector in a string" section.
http://lslwiki.net/lslwiki/wakka.php?wakka=vector