string inputText = "12345";
int value;
if (int.TryParse(inputText, out value)) // or float.TryParse, or double.TryParse etc
{
Debug.Log("The value is " + value);
}
else
{
Debug.Log("Not a valid integer");
}
But since UnityScript doesn’t support “ref” and “out” parameters, I guess, you have to use exceptions to control the code flow:
Thanks for the replies, and examples. The user in this case would be the dev. I have create a local database to .txt and a user interface to play with where you would be able to see all data types in runtime. So even though the dev would know ahead of time not to enter a string in the parsed float or int text fields. I wanted to learn something new and eliminate the error as a final polishing maneuver lol. In the game, the db will be altered by script and there wont be the concern for a mix-up in data exchange. Since I have a few customers lined up already I’d like to leave little room for error for those devs that never read the documentation.
// Needed vars
var info : String;
var outFloat : float;
var dataSetFlo : String;
// Example
if(float.TryParse(dataSetFlo, outFloat)) {
info = " Float Was Excepted";
}
else {
info = " That Was Not a Float Value";
}