• 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
Question by CG-DJ · Mar 19, 2013 at 12:57 PM · errorbugfalse

Script Errors when nothing wrong...I think

Ok, I am a beginner, so it could likely be somet$$anonymous$$ng I'm doing wrong, but I don't t$$anonymous$$nk so. I put the below script in Unity before and it worked, but now as I was editing stuff at the bottom (the About Game guiMode and the How to Play guiMode), it gave me these errors:

(17, 20 [ if(guiMode = "Main") ] ) - BCE0044: expecting ), found '=').

(17 22) - BCE0043: Unexpected token: Main.

(20, 17 [ just under //New Game Button ] ) - BCD0043: Unexpected token: if.

(20, 119) UCE0001: ';' expected. Insert a semicolon at the end.

(22, 61 [ PlayerPrefs.GetInt......] ) BCE0044: expecting :, found ';'.

 #pragma strict
 @script ExecuteInEditMode()
 
 var myGUI : GUISkin;
 var buttonWidth : float;
 var guiMode : string = "Main";
 
 function Start()
 {
     guiMode = "Main";
 }
 
 function OnGUI()
 {
     GUI.skin = myGUI;
     
     if(guiMode = "Main")
     {
         // New Game
         if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2-20, buttonWidth, 30), "New Game"))
         {
             PlayerPrefs.GetInt("playerLevel", 1);
             Debug.Log("New Game Clicked");
             Application.LoadLevel(1);
         }
         
         // Continue Game
         if(PlayerPrefs.HasKey("playerLevel"))
         {
             if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+20, buttonWidth, 30), "Continue Game"))
             {
                 Application.LoadLevel(PlayerPrefs.GetInt("playerLevel"));
             }
         }
         else
         {
             GUI.Box(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+20, buttonWidth, 30), "Continue Game");
         }
         
         //How to Play
         if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+60, buttonWidth, 30), "How to Play"))
         {
             guiMode = "HowTo";
         }
         
         //About Game
         if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
         {
             guiMode = "About";
         }
     }
     
     if(guiMode = "HowTo")
     {
         Debug.Log("How to Play");
     
         //Back to Main Menu 
         if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
         {
             Debug.Log("About Clicked");
         }
     }
     
     if(guiMode = "About")
     {
         Debug.Log("About Game");
         
         //Back to Main Menu 
         if(GUI.Button(Rect (Screen.width/2-(buttonWidth/2), Screen.height/2+100, buttonWidth, 30), "About Game"))
         {
             Debug.Log("About Clicked");
         }
     }
 }

What am I doing wrong?

Comment

People who like this

0 Show 2
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 Landern · Mar 19, 2013 at 01:02 PM 1
Share

Alucardj is spot on, a single equal sign(=) is assignment, double equal sign(==) is comparison.

= is equal to

== is it equal to

On another note, the GetInt, you have it get "playerlevel" and you use a default value of 1, but you don't have that value assigned on line 22, which if that player preference was missing would return that 1, but it wouldn't set it. For that you would use SetInt

avatar image CG-DJ · Mar 19, 2013 at 01:03 PM 0
Share

Yep that was it. I was wondering when I was supposed to use a == instead of an =. Guess its time to do more reading!

Thanks man!

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by AlucardJay · Mar 19, 2013 at 12:59 PM

start with line 17 : your conditional only has one equals sign, it needs to say "is equal to" ==

 if ( somet$$anonymous$$ng == somet$$anonymous$$ngElse ) 

 if ( guiMode == "Main" )

the same goes for all your conditionals. Check the list of operators on t$$anonymous$$s link : http://forum.unity3d.com/threads/173876-Programming-and-Making-Games-with-Unity-3D

Comment
Landern

People who like this

1 Show 0 · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

syntax errors 1 Answer

i just got unity and when i open the program i get a error saying transaction is invalid 2 Answers

press play, game objects get deleted, game breaks. 1 Answer

Screetching Sound While Walking? Why? 0 Answers

Bug for Unity 0 Answers


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