- Home /
Int to String and back to Int
I've been looking up a bunch of different stuff but nothing seems to be working. I've tried port.ToString(); and other pieces of code to try making it so the user is able to edit the text field and then right before they hit connect convert it back to an int so it can start the network. Nothing seems to be working and keep getting int can't be converted to a string.
var ipAddress : String = "127.0.0.1";
var port : int = 25000;
var maxConnections : int = 10;
function OnGUI () {
GUILayout.BeginHorizontal ();
ipAddress = GUILayout.TextField (ipAddress);
GUILayout.Label ("IP ADDRESS");
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
port = GUILayout.TextField (port);
GUILayout.Label ("PORT");
GUILayout.EndHorizontal();
if(GUILayout.Button ("CONNECT")) {
print("connecting... ");
Network.Connect (ipAddress, port);
}
if(GUILayout.Button ("START SERVER")) {
print("starting server on" + ipAddress + ":" + port);
Network.InitializeServer (maxConnections, port);
}
}
function OnConnectedToServer () {
print("connected");
}
Answer by whydoidoit · Jan 31, 2013 at 05:55 PM
System.Int32.TryParse(someString, outputInteger) is what you are looking for.
Yeah. I don't believe that tryparse will work in Javascript. Do you have a reason for using Javascript for this file?
Yeah Unity Script is great - the only problem with it is that it is called "JavaScript" which makes people think that they can read a JavaScript reference and apply those functions. $$anonymous$$any do not work, the whole language is different. Unity Script is a .NET language more similar to ActionScript than it is JavaScript. It's the biggest reason to use C# - because that's the same as C# everywhere...
Your answer

Follow this Question
Related Questions
iOS Keyboard makes performance suffer 3 Answers
GUI.TextField 1 Answer
Cannot type in textfield in Chrome on Mac 0 Answers
Check if string contains letters 1 Answer