Passing a variable from a client to server

Basically, all I want to know is how can I get a client to send a variable to the server. Here is an example of what I tried in javascript:

var MyName : String = "Example Name";//Your username
var Player1Name : String = "";//How the server will store your username

function OnConnectedToServer(){
	SendUserNameToServer();
}

@RPC
function SendUserNameToServer(){
	if(Player1Name == "")
	{
		Player1Name = MyName;
	}
}

Yes, I have attached a network view component to the gameobject holding this script. How can I get this to work properly? Thanks.

A few things wrong here.

Since SendUserNameToServer() has the @RPC attribute it is called by Unity when the RPC is received. To actually send the RPC you need to use the RPC() method on the NetworkView component.

You will also need to add a name parameter for the incoming name. Here is an example:

function OnConnectedToServer(){
    SendUserNameToServer();
}

function SendUserNameToServer(){
    networkView.RPC("SetPlayer1Name", RPCMode.Server, MyName);
}

@RPC
function SetPlayer1Name(name){
    if(Player1Name == "")
    {
        Player1Name = name;
    }
}