• 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 Digital-Phantom · Jul 14, 2013 at 08:01 AM · error messageaccessing from any scriptsemicolon

Confusing error message

OK, Ive been trying to get to grips with the whole accessing variables from another script on another object. (don't even get me started, 21+ hours now and I still don't get it...lol)

Anyway.. my latest issue is that I am getting this error message -

Assets/Scripts/SlideDoor.js(7,37): UCE0001: ';' expected. Insert a semicolon at the end.

However the line of code it refers to is -

 var gotKey : GameObject.GetComponent(PlayerInventory).hasKey;

As you can see it already has a semicolon at the end. So why am I getting this error and why is it telling me to put a semicolon at position 37 (this would not be at the end?)

Help plz guys

Comment
Add comment · Show 6
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 Bunnybomb7670 · Jul 14, 2013 at 08:08 AM 0
Share

I am not really sure but try adding () after has$$anonymous$$ey because i think it may be a function, not a variable.

avatar image Eugenius · Jul 14, 2013 at 08:11 AM 0
Share

try var got$$anonymous$$ey = GameObject.GetComponent(PlayerInventory).has$$anonymous$$ey;

avatar image Digital-Phantom · Jul 14, 2013 at 08:13 AM 0
Share

Unfortunately not, but thanks anyway.

avatar image Sprakle · Jul 14, 2013 at 08:17 AM 0
Share

Can you post the whole file, or at least the method this error resides in?

avatar image Digital-Phantom · Jul 14, 2013 at 08:19 AM 0
Share

@Eugenius, try var got$$anonymous$$ey = GameObject.GetComponent(PlayerInventory).has$$anonymous$$ey;

Gave me this -

Assets/Scripts/SlideDoor.js(7,25): BCE0020: An instance of type 'UnityEngine.GameObject' is required to access non static member 'GetComponent'.

???

Show more comments

1 Reply

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

Answer by BiG · Jul 14, 2013 at 08:16 AM

You should do

var gotKey : boolean = GameObject.Find("name").GetComponent(PlayerInventory).hasKey;

, where [name] is the object having the PlayerInventory script assigned to it.

That is: var [variable_name] : [variable_type] = [variable_assignment];

(obviously, you wasn't following this synthax, with your line of code). And, regarding the error about the missing semicolon: you are right, the semicolon was already here, but the console cannot show you always the exact error. In poor words, it has a predefined set of messages, and it shows the most suitable one for the actual situation. That's the reason for the "missing semicolon" message.

Comment
Add comment · Show 6 · 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 Digital-Phantom · Jul 14, 2013 at 08:33 AM 0
Share

noob question but does ("name") in my case it would be Player go in quotation marks ("Player") or just brackets (Player)?

when just brackets I get -

 Assets/Scripts/SlideDoor.js(7,43): BCE0005: $$anonymous$$ identifier: 'Player'.

when in quotes I get -

 Assets/Scripts/SlideDoor.js(7,83): BCE0022: Cannot convert 'boolean' to 'UnityEngine.GameObject'.

???

avatar image BiG · Jul 14, 2013 at 08:40 AM 1
Share

You are absolutely right, my bad in defining got$$anonymous$$et as a GameObject, when it's obviously a boolean var. I updated my answer. And yes, use quotation marks, around Player.

avatar image Digital-Phantom · Jul 14, 2013 at 08:44 AM 0
Share

now getting -

 UnityException: You are not allowed to call this function when declaring a variable.
 $$anonymous$$ove it to the line after without a variable declaration.
 If you are using C# don't use this function in the constructor or field initializers, Ins$$anonymous$$d move initialization to the Awake or Start function.
 SlideDoor..ctor () (at Assets/Scripts/SlideDoor.js:7)
avatar image BiG · Jul 14, 2013 at 08:47 AM 1
Share

So, that's an exposed variable (you are declaring it at the top of the script). Do just

 var got$$anonymous$$ey : boolean;

And then use

 got$$anonymous$$ey = GameObject.Find("name").GetComponent(PlayerInventory).has$$anonymous$$ey;

When you need it.

avatar image Digital-Phantom · Jul 14, 2013 at 08:55 AM 0
Share

O$$anonymous$$ I put it in the awake event and did nothing, then I read your comment again and put it into the OnTriggerEnter event and O$$anonymous$$G YAHOO it works ! ! You, my friend are a legend. Finally (after almost 24 hours I can get some sleep...lol) And what even better is I think I now understand why its working.

$$anonymous$$any, many thanks (also to all you other peeps that have helped)

:)

Show more comments

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

So my problem is that after I finished coding for my Maze I had gotten a simple error called "UCE0001: ';' expected. Insert a semicolon at the end." This here is my script and the error is on both Lines (9,15) and (10,15). 1 Answer

';' expected. Insert a semicolon at the end. I already have a ; 1 Answer

Quick error in my code? 2 Answers

Script says I need semicolons. I already have them. 1 Answer

Extra semicolon??? 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