- Home /
c# basics question.
im trying to set a PhotonPlayer variable .tostring, but its saying im not doing it in the right format. heres the code.
void OnPhotonPlayerConnected (PhotonPlayer netPlayer)
{
//Add the player to the list. This is executed on the server.
photonView.RPC("AddPlayerToList", PhotonTargets.AllBuffered, netPlayer);
}
void OnPhotonPlayerDisconnected (PhotonPlayer netPlayer)
{
//Remove the player from the list. This is executed on the server.
photonView.RPC("RemovePlayerFromList", PhotonTargets.AllBuffered, netPlayer);
}
[RPC]
void AddPlayerToList (PhotonPlayer nPlayer)
{
//Create a new entry in the PlayerList and supply the
//player's network ID as the first entry.
joinedlist = true;
Playerdataclas capture = new Playerdataclas();
capture.networkPlayer = int.Parse(nPlayer.ToString());
PlayerList.Add(capture);
}
the variable for the list is
public List<Playerdataclas> PlayerList = new List<Playerdataclas>();
its telling me im using a wrong format for the string :/ i dont get what i have to do.
FormatException: Input string was not in the correct format System.Int32.Parse (System.String s) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System/Int32.cs:629) playerdb.AddPlayerToList (.PhotonPlayer nPlayer) (at Assets/Scripts/playerdb.cs:117) * System.Reflection.$$anonymous$$ono$$anonymous$$ethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Reflection/$$anonymous$$ono$$anonymous$$ethod.cs:222) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.$$anonymous$$ono$$anonymous$$ethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Reflection/$$anonymous$$ono$$anonymous$$ethod.cs:232) System.Reflection.$$anonymous$$ethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Applications/buildAgent/work/c514da0c8183631c/mcs/class/corlib/System.Reflection/$$anonymous$$ethodBase.cs:115) NetworkingPeer.ExecuteRPC (ExitGames.Client.Photon.Hashtable rpcData, .PhotonPlayer sender) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1778) NetworkingPeer.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2657) PhotonNetwork.RPC (.PhotonView view, System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1891) PhotonView.RPC (System.String methodName, PhotonTargets target, System.Object[] parameters) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:253) playerdb.OnPhotonPlayerConnected (.PhotonPlayer netPlayer) (at Assets/Scripts/playerdb.cs:97) UnityEngine.GameObject:Send$$anonymous$$essage(String, Object, Send$$anonymous$$essageOptions) NetworkingPeer:Send$$anonymous$$ono$$anonymous$$essage(PhotonNetworking$$anonymous$$essage, Object[]) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1605) NetworkingPeer:OnEvent(EventData) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1464) ExitGames.Client.Photon.PeerBase:Deserialize$$anonymous$$essageAndCallback(Byte[]) ExitGames.Client.Photon.EnetPeer:DispatchInco$$anonymous$$gCommands() ExitGames.Client.Photon.PhotonPeer:DispatchInco$$anonymous$$gCommands() PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)
i highlited where the issue is with stars *
int.Parse() expects a string that looks like an integer, such as "21" or "42".
Have you checked what you're actually getting from nPlayer.ToString()? A simple Debug.Log() (or a peek in $$anonymous$$ono's visual debugger) can often work wonders.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
C# list bug using addRange after call toString method only on unity ios 2 Answers
Photon network doesn't call RPC/OnPhotonSerializeView 1 Answer
Using RPC to send a List 1 Answer
List clients connected? 2 Answers