- Home /
How to solve a Parsing Error
After writing my script I find when I play it I'm unable to as of an error-Parsing Eroor: What is this? Heres the problem:Assets/Scripts/MultiplayerManager.cs(2,1): error CS8025: Parsing error
Heres the script: Please reply very Urgent
edit(copied from Answer)
SORRY DIDNT REALISE I POSTED THE WRONG SCRIPT. HERE IS THE NEW SCRIPT.
1. using UnityEngine;
2. using System.Collections;
3. using System.Collections.Generic;
5. public class MultiplayerManager : MonoBehaviour
6. {
public static MultiplayerManager instance;
public GUIManager guiManager;
public GameObject PlayerManagerPrefab;
public string PlayerName;
private string MatchName = "";
private string MatchPassword = "";
private int MatchMaxUsers = 32;
public List PlayerList = new List();
public List MapList = new List();
public MapSetting CurrentMap = null;
public int oldprefix;
public bool IsMatchStarted = false;
//General Multiplayer Modes
public bool MatchLoaded;
public MPPlayer MyPlayer;
public GameObject[] Spawnpoints;
void Start()
{
instance = this;
PlayerName = PlayerPrefs.GetString("PlayerName");
CurrentMap = MapList[0];
DontDestroyOnLoad(gameObject);
}
void FixedUpdate()
{
instance = this;
}
public void StartServer(string servername, string serverpassword, int maxusers)
{
MatchName = servername;
MatchPassword = serverpassword;
MatchMaxUsers = maxusers;
Network.InitializeServer(MatchMaxUsers, 2550, false);
MasterServer.RegisterHost("DeathMatch", MatchName, "");
//Network.InitializeSecurity();
}
void OnServerInitialized()
{
Server_PlayerJoinRequest(PlayerName, Network.player);
}
void OnConnectedToServer()
{
networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
}
void OnPlayerDisconnected(NetworkPlayer id)
{
networkView.RPC("Client_RemovePlayer", RPCMode.All, id);
}
void OnPlayerConnected(NetworkPlayer player)
{
foreach(MPPlayer pl in PlayerList)
{
networkView.RPC("Client_AddPlayerToList", player, pl.PlayerName, pl.PlayerNetwork);
}
networkView.RPC("Client_GetMultiplayerMatchSettings", player, CurrentMap.MapName, "", "");
}
void OnDisconnectedFromServer()
{
PlayerList.Clear();
}
[RPC]
void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
{
networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
}
[RPC]
void Client_AddPlayerToList(string playername, NetworkPlayer view)
{
MPPlayer tempplayer = new MPPlayer();
tempplayer.PlayerName = playername;
tempplayer.PlayerNetwork = view;
PlayerList.Add(tempplayer);
if (Network.player == view)
{
MyPlayer = tempplayer;
GameObject play = Network.Instantiate(PlayerManagerPrefab, Vector3.zero, Quaternion.identity, 5) as GameObject;
//play.GetComponent<PlayerManager>().thisplayer = MyPlayer; //Remove This Part
}
}
[RPC]
void Client_RemovePlayer(NetworkPlayer view)
{
MPPlayer temppl = null;
foreach(MPPlayer pl in PlayerList)
{
if (pl.PlayerNetwork == view)
{
temppl = pl;
}
}
if (temppl != null)
{
PlayerList.Remove(temppl);
}
}
[RPC]
void Client_GetMultiplayerMatchSettings(string map, string mode, string others)
{
CurrentMap = GetMap(map);
}
public MapSetting GetMap(string name)
{
MapSetting get = null;
foreach (MapSetting st in MapList)
{
if (st.MapName == name)
{
get = st;
break;
}
}
return get;
}
[RPC]
void Client_LoadMultiplayerMap(string map, int prefix)
{
//Network.SetLevelPrefix(prefix);
Application.LoadLevel(map);
}
void OnGUI()
{
if (!MyPlayer.PlayerIsAlive && IsMatchStarted)
SpawnMenu();
if (IsMatchStarted && Input.GetKey(KeyCode.Tab))
{
guiManager.ScoreBoard();
}
}
[RPC]
void Server_SpawnPlayer(NetworkPlayer player)
{
int numberspawn = Random.Range(0, Spawnpoints.Length - 1);
networkView.RPC("Client_SpawnPlayer", RPCMode.All, player, Spawnpoints[numberspawn].transform.position + new Vector3(0, 2, 0), Spawnpoints[numberspawn].transform.rotation);
}
[RPC]
void Client_SpawnPlayer(NetworkPlayer player, Vector3 position, Quaternion rotation)
{
MultiplayerManager.GetMPPlayer(player).PlayerIsAlive = true;
MultiplayerManager.GetMPPlayer(player).PlayerHealth = 100;
if (player == MyPlayer.PlayerNetwork)
{
MyPlayer.PlayerManager.ControllerTransform.position = position;
MyPlayer.PlayerManager.ControllerTransform.rotation = rotation;
MyPlayer.PlayerManager.networkView.RPC("Client_PlayerAlive", RPCMode.All);
}
else
{
}
}
void OnLevelWasLoaded()
{
if (Application.loadedLevelName == CurrentMap.MapLoadName && Network.isServer)
{
MatchLoaded = true;
Spawnpoints = GameObject.FindGameObjectsWithTag("spawnpoint");
networkView.RPC("Client_ServerLoaded", RPCMode.AllBuffered, IsMatchStarted);//Add parameter for boolean IsMatchStarted
}
}
[RPC]
void Client_ServerLoaded(bool started)//Add parameter for boolean IsMatchStarted
{
MatchLoaded = true;
IsMatchStarted = started;
}
public static MPPlayer GetMPPlayer(NetworkPlayer player)
{
foreach (MPPlayer play in MultiplayerManager.instance.PlayerList)
{
if (play.PlayerNetwork == player)
{
return play;
}
}
return null;
}
//Deathmatch
void SpawnMenu()
{
if (GUI.Button(new Rect(5, Screen.height - 40, 250, 35), "Spawn"))
{
if (Network.isServer)
Server_SpawnPlayer(Network.player);
else
networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);
}
}
[RPC]
public void Client_UpdatePlayerHealthAndAlive(NetworkPlayer targetplayer, bool IsAlive, int CurrentHealth)
{
MPPlayer player = MultiplayerManager.GetMPPlayer(targetplayer);
player.PlayerIsAlive = IsAlive;
player.PlayerHealth = CurrentHealth;
}
231. }
233. [System.Serializable]
234. public class MPPlayer
235. {
public string PlayerName = "";
public NetworkPlayer PlayerNetwork;
public PlayerManager PlayerManager;
public int PlayerHealth = 100;
public bool PlayerIsAlive;
public int PlayerScore;
public int PlayerKills;
public int PlayerDeahts;
244. }
246. [System.Serializable]
247. public class MapSetting
248. {
public string MapName;
public string MapLoadName;
public Texture MapLoadTexture;
252. }
Your parsing error is in the $$anonymous$$ultiplayer$$anonymous$$anager script, but you posted your $$anonymous$$enu$$anonymous$$anager script. Please post the correct script and we'll be happy to resolve your concern.
Alternatively, if this script is saved as $$anonymous$$ultiplayer$$anonymous$$anager.cs, the class should also be called $$anonymous$$ultiplayer$$anonymous$$anager
@perchik is correct. If the class name and script name don't match in C#, a warning will be thrown.
as a side note: so, i only glanced over your code, but unless i'm missing something, there's no reason to continuously assign:
instance = this
as you have done here in the fixedupdate() loop. assign it once at start and you're set.
Answer by Bunny83 · Aug 09, 2013 at 06:36 AM
Well, is it possible that you have that 1. 2. 3. .... actually in your script file? Remove them, all!
Btw, that looks like a compy and paste error from aoms website. This script actually exists in more or less this form several times on the net:
http://mysticpaste.com/view/5oD1v6UOOk;jsessionid=1yia78vgd5zp2a4pmnpprwu?0
$$anonymous$$y edited script? I did not edit any script, I just copied your script from the answer you've posted to your question since answers should answer the question. As I said it seems you copied line numbers into the script itself. Those numbers are not code. They must be removed.
Do a little homework on parsing man. Google it. "Parsing Error C#". It's probably either an unnecessary or missing bracket. Opening { Bracket or Closing } Bracket.
In addition to @Bunny83's answer, don't number each line!
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class $$anonymous$$ultiplayer$$anonymous$$anager : $$anonymous$$onoBehaviour
{
public static $$anonymous$$ultiplayer$$anonymous$$anager instance;
public GUI$$anonymous$$anager gui$$anonymous$$anager;
public GameObject Player$$anonymous$$anagerPrefab;
public string PlayerName;
private string $$anonymous$$atchName = "";
private string $$anonymous$$atchPassword = "";
private int $$anonymous$$atch$$anonymous$$axUsers = 32;
public List PlayerList = new List();
public List $$anonymous$$apList = new List();
public $$anonymous$$apSetting Current$$anonymous$$ap = null;
public int oldprefix;
public bool Is$$anonymous$$atchStarted = false;
//General $$anonymous$$ultiplayer $$anonymous$$odes
public bool $$anonymous$$atchLoaded;
public $$anonymous$$PPlayer $$anonymous$$yPlayer;
public GameObject[] Spawnpoints;
void Start()
{
instance = this;
PlayerName = PlayerPrefs.GetString("PlayerName");
Current$$anonymous$$ap = $$anonymous$$apList[0];
DontDestroyOnLoad(gameObject);
}
void FixedUpdate()
//.........................And so on..........
Your answer
