- Home /
Basic networking script
I need help, I can't find my error. Could it just be my network doesn't allow me to host? But shouldn't I be able to connect to my own IP address as well? Anyways I can't get the error I tried several thing. Can someone come help, very new to networking.
var spawnPoint: Transform;
var gameName: String;
private var refreshing: boolean;
private var hostData: HostData[];
function Start () {
gameName = "This_Pirate_Game_Rocks_12";
}
function Update () {
if (!Network.isClient) {
refreshHostList();
Debug.Log("Refreshing List");
if (refreshing) {
hostData = MasterServer.PollHostList();
Debug.Log("Getting hostData");
if (hostData) {
if (hostData.Length <= 0) {
Debug.Log("No sever found. Starting sever.");
startServer();
Debug.Log(hostData.Length);
}
else {
Network.Connect(hostData[0]);
Debug.Log("You're connect to the server!");
}
}
}
}
}
function spawnPlayer() {
Network.Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity, 0);
}
function startServer() {
Network.InitializeServer(32,25001, !Network.HavePublicAddress);
MasterServer.RegisterHost(gameName, "Wonderful Pirate Game", "HI");
Debug.Log("Created server!");
}
function refreshHostList() {
MasterServer.RequestHostList(gameName);
refreshing = true;
}
function OnConnectedToServer() {
spawnPlayer();
}
I put debug log codes in and everything is running. But I'm not sure what the error is. The last line of code which is access is this one
Debug.Log(hostData.Length); and it returns 0 every time so I am taking a guess and it isn't initializing my server.
Help please? Thanks.
Answer by maroien88 · Jan 24, 2013 at 12:30 AM
remplace the line MasterServer.RegisterHost(gameName, "Wonderful Pirate Game", "HI");
with this and test
MasterServer.RegisterHost("This_Pirate_GR_12", "Wonderful_Pirate", "l33t game for all");
Did not help. If it was because you think gameName was null or undefined then you're incorrect cause it does have a value.