- Home /
Help with BCE0044 and UCE001 error in my script!
I need help in my script which has two compile errors... "Assets/Scripts/OnPlayerConnectDeathmatch.js(24,27): BCE0044: expecting :, found ';'" and "Assets/Scripts/OnPlayerConnectDeathmatch.js(23,47): UCE0001: ';' expected. Insert a semicolon at the end".
This is my code:
var player1 : Transform;
var player2 : Transform;
var player3 : Transform;
var player4 : Transform;
var player5 : Transform;
var player6 : Transform;
var player7 : Transform;
var player8 : Transform;
var spawnpoint1 : GameObject;
var spawnpoint2 : GameObject;
var spawnpoint3 : GameObject;
var spawnpoint4 : GameObject;
var spawnpoint5 : GameObject;
var spawnpoint6 : GameObject;
var spawnpoint7 : GameObject;
var spawnpoint8 : GameObject;
function OnNetworkLoadedLevel () {
if (spawnpoint1.CompareTag("Empty")) {
Network.Instantiate(player1, spawnpoint1.transform, spawnpoint1.rotation);
spawnpoint1.tag = "Used";
}
else (spawnpoint1.CompareTag("Used")) {
GoToSpawn2 ();
}
}
function GoToSpawn2 () {
if (spawnpoint2.CompareTag("Empty")) {
Network.Instantiate(player2, spawnpoint2.transform, spawnpoint2.rotation);
}
else (spawnpoint2.CompareTag("Used")) {
GoToSpawn3 ();
}
}
function GoToSpawn3 () {
if (spawnpoint3.CompareTag("Empty")) {
Network.Instantiate(player3, spawnpoint3.transform, spawnpoint3.rotation);
}
else (spawnpoint3.CompareTag("Used")) {
GoToSpawn4 ();
}
}
function GoToSpawn4 () {
if (spawnpoint4.CompareTag("Empty")) {
Network.Instantiate(player4, spawnpoint4.transform, spawnpoint4.rotation);
}
else (spawnpoint4.CompareTag("Used")) {
GoToSpawn5 ();
}
}
function GoToSpawn5 () {
if (spawnpoint5.CompareTag("Empty")) {
Network.Instantiate(player5, spawnpoint5.transform, spawnpoint5.rotation);
}
else (spawnpoint5.CompareTag("Used")) {
GoToSpawn6 ();
}
}
function GoToSpawn6 () {
if (spawnpoint6.CompareTag("Empty")) {
Network.Instantiate(player6, spawnpoint6.transform, spawnpoint6.rotation);
}
else (spawnpoint6.CompareTag("Used")) {
GoToSpawn7 ();
}
}
function GoToSpawn7 () {
if (spawnpoint7.CompareTag("Empty")) {
Network.Instantiate(player7, spawnpoint7.transform, spawnpoint7.rotation);
}
else (spawnpoint7.CompareTag("Used")) {
GoToSpawn8 ();
}
}
function GoToSpawn8 () {
if (spawnpoint8.CompareTag("Empty")) {
Network.Instantiate(player8, spawnpoint8.transform, spawnpoint8.rotation);
}
else (spawnpoint8.CompareTag("Used")) {
Network.Disconnect();
}
}
}
Answer by phren · Jun 13, 2012 at 11:19 AM
The problem here is that you're using else statements with conditions. In this case you should be using else if. I would however prescribe a refactoring of the code in this manner:
var players : Transform[];
var spawnPoints : Transform[];
function OnNetworkLoadedLevel(){
for(var i = 0; i < players.length && i < spawnPoints.length; i++){
if(spawnPoints[i].CompareTag("Empty")){
Network.Instantiate(players[i], spawnPoint[i].transform.position, spawnPoint[i].transform.rotation);
spawnPoint[i].tag = "Used";
} else if(i == spawnPoints.length-1){
Network.Disconnect();
}
}
}
By restructuring your code like this you can add new spawn points and remove old ones more easily. Also with less lines of code you're probably going to introduce fewer bugs. :)
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
A node in a childnode? 1 Answer
Fatal Error When I Load Unity 0 Answers
Player lives script help 1 Answer