- Home /
The question is answered, right answer was accepted
Multiplayer Script error
I am a novice at Unity, and was making a Javascript to make a direct connect lobby system for a game i'm working on. But keep getting 2 errors: No appropriate version of 'UnityEngine.Network.InitializeServer' for the argument list '(int, String)' was found.
and Cannot Convert 'int' to 'String'
how can i fix these?
#pragma strict
var remoteIPadress = "127.0.0.1";
var remotePort = "25000";
var listenPort = "25000";
var useNAT = true;
var myIP = "";
var myPort = "";
var MaxPlayer = 32;
function OnConnectedToServer ()
{
}
function OnDisconnectedToServer ()
{
}
function OnGUI ()
{
if(Network.peerType == NetworkPeerType.Disconnected)
{
if(GUI.Button(Rect(5,5,60,30),"Connect"))
{
Network.useNat = useNAT;
Network.Connect(remoteIPadress, remotePort);
}
if(GUI.Button(Rect(5, 40, 60, 30),"StartServer"))
{
Network.useNat = useNAT;
Network.InitializeServer(MaxPlayer,listenPort);
}
remoteIPadress = GUI.TextField(Rect(5, 75, 60, 30),remoteIPadress);
remotePort = parseInt(GUI.TextField(Rect(5, 10, 60, 30),remoteIPadress));
}
else
{
if(GUI.Button(Rect(5,5,60,30),"Disconnect"))
{
Network.Disconnect(200);
}
}
}
Answer by ByteSheep · May 10, 2013 at 03:07 AM
http://docs.unity3d.com/Documentation/ScriptReference/Network.InitializeServer.html
Network.InitializeServer() requires the first two parameters to be integer values.
In your code the second value (listenPort) is a string, so you need to change the declaration to:
var listenPort = 25000;
1 error down, 1 to go,
Line 41: Cannot convert int to string. must...solve...on...own
Again the same problem - your remotePort variable is declared as a string, but on line 41 you are trying to assign an int value to it. So again the new line would look like:
var remotePort = 25000;
Answer by small-U · May 10, 2013 at 03:49 AM
static function InitializeServer (connections : int, listenPort : int, useNat : bool) : NetworkConnectionError
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error CS1502 Help! 1 Answer
Error CS1502 help! 1 Answer
Error UCE0001 ";"Expected 2 Answers
2D bullet script errors. 1 Answer