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 markzareal · Aug 20, 2014 at 10:29 PM · javascripterror

Error I don't know how to fix

Heres my code:

 #pragma strict

 var text : GUIText;
 
 var object : GameObject;
 
 var diamond : Sprite;
 
 var circle : Sprite;
 
 var triangle : Sprite;
 
 var square : Sprite;
 
 var number : int;
 
 var spriteRenderer; 
 
 var target : Timer;
 
 var AcceptInput : boolean = true;
 
 static var score : int = 0;
 
 static var guiScore : GUIText;
 
 
 function Start () {
 
 spriteRenderer = object.GetComponent(SpriteRenderer);
 
 number = Random.Range(1,4);
 
 if(number == 1) {
 
 spriteRenderer.sprite = diamond;
 
 }
 
 else if(number == 2) {
 
 spriteRenderer.sprite = circle;
 
 }
 
 else if (number == 3) {
 
 spriteRenderer.sprite = triangle;
 
 }
 
 else {
 
 spriteRenderer.sprite = square;
 
 }
 }
 
 
 function Update () {
 
 if(Input.GetMouseButtonDown(0)) {
 
 if(AcceptInput) {
 
 AcceptInput = false;
 
 text.enabled = false;
 
 target.enabled = true;
 
 Debug.Log("Clicked");
 
 if(object.GetComponent(SpriteRenderer).sprite == diamond) {
 
 score += 1;
 
 guiScore.text = "Score: " + score;
 
 StartCoroutine("YieldTestEnumerator");
 
 spriteRenderer = object.GetComponent(SpriteRenderer);
 
 number = Random.Range(1,4);
 
 if(number == 1) {
 
 spriteRenderer.sprite = diamond;
 
 }
 
 else if(number == 2) {
 
 spriteRenderer.sprite = circle;
 
 }
 
 else if (number == 3) {
 
 spriteRenderer.sprite = triangle;
 
 }
 
 else {
 
 spriteRenderer.sprite = square;
 
 }
 
 }
 
 if(object.GetComponent(SpriteRenderer).sprite == circle) {
 
 Debug.Log("Wrong Answer!");
 
 Application.LoadLevel("GameOver");
 
 }
 
 if(object.GetComponent(SpriteRenderer).sprite == triangle) {
 
 Debug.Log("Wrong Answer!");
 
 Application.LoadLevel("GameOver");
 
 }
 
 if(object.GetComponent(SpriteRenderer).sprite == square) {
 
 Debug.Log("Wrong Answer!");
 
 Application.LoadLevel("GameOver");
 
 }
 
 if(Input.GetMouseButtonUp(0)) {
 AcceptInput = true;
 }
 }
 }
 
 function YieldTestEnumerator () {
 yield WaitforSeconds (0.5);
 }
 

but it gives the following errors:

 Assets/Scripts/GAME/buttons/Diamond.js(142,10): BCE0044: expecting (, found 'YieldTestEnumerator'.
  
 Assets/Scripts/GAME/buttons/Diamond.js(142,32): UCE0001: ';' expected. Insert a  semicolon at the end.
  
 Assets/Scripts/GAME/buttons/Diamond.js(145,1): BCE0044: expecting }, found ''.

But I don't find anything wrong with this last bit:

 function YieldTestEnumerator () {
 yield WaitforSeconds (0.5);
 }

All of the errors seem to be in that area. Do you have any ideas?

Comment
Add comment · Show 3
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 rutter · Aug 20, 2014 at 10:33 PM 0
Share

Are you showing the right script file? The error message indicates line 142 of a file named Diamond.js, but you've only posted 74 lines of script.

avatar image Kiwasi · Aug 21, 2014 at 12:11 AM 0
Share

Want to post the relevant portion of code?

Unexpected symbol is often due to the line before the error. Check for line endings, matched braces ect.

avatar image markzareal · Aug 21, 2014 at 07:11 AM 0
Share

oops sorry I'll update the code @rutter

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by HarshadK · Aug 21, 2014 at 07:28 AM

You need to close your Update loop.

You need to put a closing bracket before the function YieldTestEnumerator () {

So it would become:

 if(Input.GetMouseButtonUp(0)) {
     AcceptInput = true;
 }
 }
 }
 }
Comment
Add comment · Show 5 · 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 markzareal · Aug 21, 2014 at 07:40 AM 0
Share

Thank you so much! But then it gives me these errors:

 Assets/Scripts/GA$$anonymous$$E/buttons/Diamond.js(36,16): BCE0019: 'sprite' is not a member of 'Object'. 

and theres a whole bunch of them that is the same error. Do you know why?

avatar image HarshadK · Aug 21, 2014 at 07:43 AM 0
Share

Do not use 'object' as as a variable name since it is a reserved keyword.

Change the name of your Game Object to anything else than 'object'.

avatar image markzareal · Aug 21, 2014 at 08:09 AM 0
Share

Ok thanks dude

avatar image markzareal · Aug 21, 2014 at 09:17 AM 1
Share

Actually, it didn't work. it still said the same error. What's wrong with this code? I changed to var anything : GameObject

avatar image markzareal · Aug 21, 2014 at 10:14 AM 1
Share

never$$anonymous$$d it was because I had to change it to if(object.GetComponent(SpriteRenderer).sprite == diamond)

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

23 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

BCE0049 error with network script 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

"Expecting ), found ';'" and "';' expected. Insert a semicolon at the end" 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