Convert a float to a string.

How do I do it? (JavaScript)

Doesn’t .ToString () work?

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.

throw myString;

Huh, I’ve never seen that used before. So “throw” can be used to remove variables? Is it worth doing?

I think it just prints a message. It’s similar to Debug.LogError (), i think.

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:

	// 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

Thanks for clarifying it.