Doesn't .ToString () work? Code (csharp): function Start () { var myFloat : float = 5.5; var myString : String = myFloat.ToString (); throw myString; }
It did. I have no idea what I did not do right, because I could have sworn I did what you wrote. Anyway, it's working now. Hooray! Thanks a ton.
Code (csharp): throw myString; Huh, I've never seen that used before. So "throw" can be used to remove variables? Is it worth doing?
throw is for catching exceptions, errors, ect.. (this is checking if the string is null or not). It's like C's assert or C++'s throw/catch.
Here's how you use throw: Code (csharp): // Try to read an integer value from a string try { var newSize = parseInt(levelSizeString); // If parsing worked but the values are too silly if (newSize < 2 || newSize > 99) { throw "Bad data"; } } // If reading the value didn't work, do nothing catch (err) { print (err.Message); return; } // Otherwise use the string's value LevelEditor.setSize = newSize; (Adapted from one of my recent scripts.) You can use it to generate exceptions, like in those cases where something technically works, but you want it to fail anyway. In this case, parseInt will generate an exception if it tries to parse something like "226saQQ!!!" because of the non-numerical data, but I also wanted to fail for certain legal values too. --Eric