Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MadOne1 · Jan 10, 2012 at 06:59 AM · javascriptguitimer

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by BiG · Jan 10, 2012 at 07:16 AM

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).

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lo0NuhtiK · Jan 10, 2012 at 07:18 AM 1
Share

lol you beat me typing by like 27 seconds :D


+1
Edit ... I didn't notice the "var" missing from gameOver though ... looks like you didn't notice the uppercase CurrentTime ... maybe between the two of us we got em all lol

avatar image BiG · Jan 10, 2012 at 07:21 AM 1
Share

Ah ah! ;)

  • to you, as well.

Edit...Ehm...You're right! ;)

avatar image Lo0NuhtiK · Jan 10, 2012 at 07:22 AM 0
Share

Thanks :D 

avatar image
3

Answer by Lo0NuhtiK · Jan 10, 2012 at 07:17 AM

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
try fixing those and see if anything changes.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MadOne1 · Jan 10, 2012 at 09:40 AM

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BiG · Jan 10, 2012 at 09:54 AM 0
Share

Try substituting time.currentTime == 0 with currentTime == 0. I don't get the sense in using "time", here.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Timer Between Labels 2 Answers

Setting Scroll View Width GUILayout 1 Answer

How Would I Make A GUI Label Fade After A Certain Amount Of Time? 1 Answer

How to see minutes in the timer's box? 1 Answer

I get a weird error when i try to use GUISkin on a timer 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges