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 Kehros · Sep 25, 2013 at 11:20 AM · iflearningelse

IF - ELSE Issue! (Help! I'm new to this)

Hey all, I'm just learning how to script using javascript for Unity. I've just started and learnt a bit about if and else statements, however I am pulling my hair out of frustration now able to work out an error I keep having. I've been through a lot of answers on this website for the trouble I'm having and nothing seems to be helping. I keep getting

 'BCE0044: expecting }, found 'else'.

Here are two scripts I wrote, A) gives me errors, B) doesn't. Sorry if this is an easy fix, I have researched and I cannot find any answers as to what is wrong with my script.

Script A) (Gives me error codes)

      var pickupKey         = true;                                    
     var openDoor         = false;                                
     var numberOfKeys    = 1;                                    
     var keysAmount         = 0;                                    
 
 
 function Start (){
 }
 function Update (){
        numberOfKeys = numberOfKeys + 1;
      keysAmount = numberOfKeys;
      print (numberOfKeys);
      
           numberOfKeys = numberOfKeys + 1;
            keysAmount = numberOfKeys;
      print (numberOfKeys);
      
          numberOfKeys ++;
          print (numberOfKeys);
          keysAmount = numberOfKeys;
          print ("You have " + keysAmount + " keys in your bag!");
          print ("Because of this....");
          
          if (keysAmount >= 3);
          {
              print ("The door has now opened!");
              openDoor = true;
              numberOfKeys -= 3;
              
               print ("Now you have " + numberOfKeys + " keys");
          }     
          
          else
          {
              print ("Not enough keys to open the door");
              }
 
 }

SCRIPT B) (No error codes but I don't see anything I did any different)

 function Start () {
 }
 
 function Update()
 {
 
      var luckyNumber = 6;
      
      if (luckyNumber == 5)
      {
          print ("Lucky number equals 5");
      }
      
      else
      {
          print ("Lucky number does NOT equal 5");
          }
 }



Thank you for your time and sorry if this was a bit hard to read, this is my first time using this website so I was a bit unsure how to format this post to make it look cleaner. Please tell me what I've been doing wrong.

Comment
Add comment · Show 1
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 Graham-Dunnett ♦♦ · Sep 25, 2013 at 11:24 AM 0
Share

Because you are new around here, I formatted your question to give the community half a chance at helping you. Please watch the video that $$anonymous$$ches you how to use the site.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Graham-Dunnett · Sep 25, 2013 at 11:23 AM

Remove the semi-colon at the end of line 24.

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 Kehros · Sep 25, 2013 at 01:03 PM 0
Share

Thanks for the quick replies, and thanks for restructuring my post Graham, I'll check out the video for future posts. Also, removing the semi-colon at the end of line 24 just added another error message which was to put it back on.

I can avoid it for now if I have to, after following a tutorial it was said it was a fundamental so I was trying to learn everything I could from it (from walkerboystudio.com)

It just seems like a really good feature to learn before I move ahead with more complex stuff.

avatar image hamstar · Sep 25, 2013 at 02:04 PM 0
Share

As he said, remove semi-colon on this line if (keysAmount >= 3);. Tested in Unity and there are no more errors. Tip: double click on the error in the debug window and it will take you to the area of code with mistake.

avatar image Kehros · Sep 25, 2013 at 02:28 PM 0
Share

Thank you guys for all your help, hamstar yours was right, this fixed it right up and now I can see the mistake I made. Thanks again!

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

19 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

Related Questions

Multiple Cars not working 1 Answer

Why am i getting this error?! 2 Answers

Button if else statement? 1 Answer

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer

Both if and else are running, because else condition is met after if 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