- Home /
Problem Displaying gameName when refreshing masterserver
I'm trying to start a simple server. I'm not getting any errors, the server starts, registers, and I can refresh and print 1 server is available.
The problem is when I try creating a GUIButton that prints the Game Name variable (after the server is created). The button fails to appear and I don't know why.
Here's the complete code (it runs), and I'm suspecting the problem is on the for loop, in the OnGUI Function. Thanks in advance.
var buttonY : float;
var buttonW : float;
var buttonH : float;
function Start (){
buttonX = Screen.width * 0.05;
buttonY = Screen.width * 0.05;
buttonW = Screen.width * 0.1;
buttonH = Screen.width * 0.1;
}
function startServer(){ //4
Network.InitializeServer(32,25001, !Network.HavePublicAddress);
MasterServer.RegisterHost(gameName,"Awesome Possum Server", "You'll be a boring cube.");
}
function refreshHostList(){ //5
MasterServer.RequestHostList(gameName);
refreshing = true;
MasterServer.PollHostList();
Debug.Log(MasterServer.PollHostList().Length);
}
function Update(){
if(refreshing){
if(MasterServer.PollHostList().Length > 0){
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
MasterServer.PollHostList();
}
}
}
// Messages
function OnServerInitialized(){ // 2
Debug.Log("Server is up and ready...");
}
function OnMasterServerEvent(mse:MasterServerEvent){ //3
if(mse == MasterServerEvent.RegistrationSucceeded){
Debug.Log("Registered Server!");
}
}
//GUI
function OnGUI(){ // 1
if( GUI.Button(Rect(buttonX,buttonY,buttonW,buttonH),"Start Server") ){
Debug.Log("Starting Server");
startServer();
}
if( GUI.Button(Rect(buttonX,buttonY * 1.2 + buttonH,buttonW,buttonH),"Refresh Servers") ){
Debug.Log("Refreshing Servers");
refreshHostList();
}
if(hostData){
for(var i:int = 0; i<hostData.length; i++){
GUI.Button(Rect(buttonX * 1.5 + buttonW, buttonY*1.2 + (buttonH *i), buttonW*3, buttonH*0.5),hostData[i].gameName);
}
}
}