Hey :)
So ive been following a tutorial and have this code as working progress for networking and when i build the game and have run in background on, nothing happens. On one game it says server initialized and then when i try to join the game on the other it wont allow me to. any ideas of what im doing wrong?
var gameName: String ="Atomizer_Networking_Curtis";
private var refreshing: boolean;
private var hostData: HostData[];
private var btnX: float;
private var btnY: float;
private var btnW: float;
private var btnH: float;
function Start(){
btnX = Screen.width * 0.1;
btnY = Screen.width * 0.1;
btnW = Screen.width * 0.1;
btnH = Screen.width * 0.1;
}
function startServer(){
Network.InitializeServer(4, 25001, !Network.HavePublicAddress);
MasterServer.RegisterHost(gameName,"Tutorial Game Name","This is a tutorial game");
}
function refreshHostList(){
MasterServer.RequestHostList(gameName);
refreshing = true;
}
function Update(){
if(refreshing){
if(MasterServer.PollHostList().Length > 0){
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
hostData = MasterServer.PollHostList();
}
}
}
// Messages
function OnServerInitialized(){
Debug.Log("Server Initialized!");
}
function OnMasterServerEvent(mse:MasterServerEvent){
if(mse == MasterServerEvent.RegistrationSucceeded){
Debug.Log("Registered Server!");
}
}
//GUI
function OnGUI(){
if(!Network.isClient && !Network.isServer){
if(GUI.Button(Rect(btnX, btnY, btnW, btnH), "Start")){
Debug.Log("Starting Server");
startServer();
}
if(GUI.Button(Rect(btnX, btnY * 1.2 + btnH, btnW, btnH), "Refresh")){
Debug.Log("Refreshing");
refreshHostList();
}
if(hostData){
for(var i : int = 0; i < hostData.length; i ++ ){
if(GUI.Button(Rect(btnX * 1.5 + btnW, btnY * 1.2 + (btnH * i), btnW * 3, btnH * 0.5), hostData*.gameName));*
_ Network.Connect(hostData*);_
_ }_
_ }_
_ }_
_}*_
Please format your code next time. It is done by selecting your code and pressing the "10101" button. I have done it for you now, but I would like to stress the importance of doing so the next time.
– FLASHDENMARK"It won't allow me to". There are a lot of things that could mean. What exactly happens when you try to join?
– Dave-Carlile