How do I create a server selection menu?

Hello everyone! Been a while since i’ve been on here. Unity has kept me busy ;).

Now to business:

I have been knocking up a prototype for a game, all coming along fine. But as a little learning project for myself I want to implement some basic networking. Namely, create a MasterServer type connection and see each other running about. Now everything has been going smoothly, until I tried to create the menu.

Now the specific issue i’m having is with creating the “Server selection menu”. You have all seen these (I would expect). You are presented with a list of servers, you can select one and press “Join” or “Connect” or what-have-you.

Here’s my most recent attempt:

//creating server selection menu element
var hostdata : HostData[] = MasterServer.PollHostList();
for (var element in hostdata)
{
	GUILayout.BeginHorizontal();
		var connections = element.connectedPlayers + "/" + element.playerLimit;
		GUILayout.Label(element.gameName);
		GUILayout.Space(5);
		GUILayout.Label(connections);
		GUILayout.Space(5);
	GUILayout.EndHorizontal();	
	}

Now to me, that says: “Grab the hostdata from the function PollHostList, for each entry in that array create 2 labels in a horizontal layout”.

Unity seems to think this means: “Sit here idly with a blank face”.

I’m guessing I’m missing some fundamental here. The “for(var element in hostdata)” I’m not entirely sure on, it’s something I picked up on from the docs and examples. I’m guessing “elements” means… an element in the array, but I’m probably wrong.

Could someone slap me round the face, tell me to stop being an idiot and point me in the right direction please? (the slap is optional).

Thanks for reading everyone, I hope you can help me.

To give an example of what @syclamoth said:

function JoinGame(element : HostData)
{
    Network.Connect(element);
}

And in your loop just add the button:

    [...]
    GUILayout.Label(connections);
    GUILayout.Space(5);
    if(GUILayout.Button ("Join"))
    {
        JoinGame(element);
    }        
    GUILayout.EndHorizontal();  
}