gameoverscript.js(1,1): BCE0044: expecting EOF, found 'gameOver'.

i have two pieces of script ones the timer, the other is the GUI once it gets to 0 i want ti disply game over for the time being. Im new to unity any suggestions as to what this error is all about that would be great and how i can fix would be even better.


Below is the timer code

// the textfield to update the time to
private var textfield:GUIText;

// time variables
public var allowedTime:int = 5;
private var currentTime = allowedTime;

function Awake()
{
// retrieve the GUIText Component and set the text
textfield = GetComponent(GUIText);

UpdateTimerText();

// start the timer ticking
TimerTick();

}

function UpdateTimerText()
{
// update the textfield
textfield.text = currentTime.ToString();
}

function TimerTick()
{
// while there are seconds left
while(currentTime > 0)
{
// wait for 1 second
yield WaitForSeconds(1);

    // reduce the time
    currentTime--;

    UpdateTimerText();
}

//gameover
}


This snippet is the GUI

gameOver : boolean = false;

function Update()
{
if (CurrentTime = 0)
gameOver = true;

}

function OnGUI()
{
if (gameOver)
GUI.Label(Rect(0,0, 100, 20), “Game Over”);

}

Help would be very much appreciated.

Thanks

Your error is due to the line “gameOver : boolean = false;”: add the word “var” at the beginning, like that:

var gameOver : boolean = false;

However, there’s another error, two lines ahead:

if (CurrentTime = 0) 

is a test, not an assignment, so it would be:

if (CurrentTime == 0)

If your script wouldn’t work yet, my advice is to format the code properly in the question, so it will be more readable (just click on the 010101 button).

You’ve got two errors in Update() that I can see …

if(CurrentTime = 0)…
your CurrentTime variable is ‘currentTime’ not CurrentTime (case-sensitive)
and only one equals sign

…->

if(currentTime == 0) is what would be used for equal-to…

I’d go with this though->

if(currentTime <= 0 ) … just in case the timer drops under zero.

try fixing those and see if anything changes.

I having made changes to the code.

However the problem im having now is the “game over” message is appearing before the timer gets to 0.

------------timerscript--------------------

// the textfield to update the time to

private var textfield:GUIText;

// time variables
public var allowedTime:int = 5;
var currentTime = allowedTime;

function Awake()
{
// retrieve the GUIText Component and set the text
textfield = GetComponent(GUIText);

UpdateTimerText();

// start the timer ticking
TimerTick();

}

function UpdateTimerText()
{
// update the textfield
textfield.text = currentTime.ToString();
}

function TimerTick()
{
// while there are seconds left
while(currentTime > 0)
{
// wait for 1 second
yield WaitForSeconds(1);

    // reduce the time
    currentTime--;

    UpdateTimerText();
}

// game over
//yield WaitForSeconds (10);
//Application.LoadLevel ("Menu");

}

----------------game over script-----------------

var gameOver : boolean = false;

var time : CountdownTimer;

function Update()
{
if (time.currentTime == 0)
gameOver = true;

}

function OnGUI()
{
if (gameOver)
GUI.Label(Rect(0,0, 100, 20), “Game Over”);

}

Thanks for all the previous feedback!