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 Inksprout · Oct 18, 2011 at 03:31 AM · variableglobalbooleans

Why can't I acces my global variable?

I have a tool in the game I am making that is supposed to absorb one unit of water and then place it somewhere else when you fire at the other place. I want to make it so that the player could only collect one unity of water at a time so I made a global variable called waterfull to see if the player's watertank is full or not. Its supposed to not absorb water when the tank is full. However when I try to check if the global variable waterfull is fall (true) or empty (false) from a different script unity says BCE0005: Unknown identifier: 'WaterApparatus'. WHY???? All the script reference says To access it from another script you need to use the name of the script followed by a dot and the global variable name.print(TheScriptName.someGlobal); TheScriptName.someGlobal = 10;

As far as I am concerned that is what I did. How I declared the variable in a separate script called waterApparatus:

 static var waterfull : boolean = false;

Where I am trying to use this variable to check if the player has already absorbed water:

function OnTriggerEnter (other : Collider) {
  if (other.gameObject.CompareTag ("water") && waterApparatus.waterfull==false){
    WaterApparatus.waterfull=true;
    Destroy(other.gameObject);
  } 
}

Comment
Add comment · 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 Mikbe · Oct 18, 2011 at 03:42 AM 2
Share

I answered but this site hates my freedom.

Change the third line from Pascal case WaterApparatus to camel case waterApparatus.

avatar image syclamoth · Oct 18, 2011 at 04:26 AM 2
Share

Or, alternatively, do the right thing and replace waterApparatus in your class name with WaterApparatus. Upper case for type names, lower case for member names.

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Mikbe · Oct 18, 2011 at 04:04 AM

On the second line you have waterApparatus but on the third line you have uppercase WaterApparatus.

 function OnTriggerEnter (other : Collider) {
   if (other.gameObject.CompareTag ("water") && waterApparatus.waterfull==false){
     WaterApparatus.waterfull=true;
     Destroy(other.gameObject);
   } 
 }
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 Eric5h5 · Oct 18, 2011 at 03:42 AM

Static and global are two different things, and shouldn't be conflated. Anyway, check your spelling, you made a typo in the script.

Comment
Add comment · Show 16 · 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 Mikbe · Oct 18, 2011 at 03:46 AM 0
Share

Your "answer" is why I think I'm giving up on this site. You have tens of thousands of points but don't bother to actually help where I have none and can't help because I have no points. This StackOverflowification of communities is destroying them. I'm out.

avatar image syclamoth · Oct 18, 2011 at 04:25 AM 0
Share

@$$anonymous$$ikbe, you've been here for less than 2 weeks, and made exactly 4 posts. Of course you don't have many points yet! Post good answers, and you'll get upvoted.

avatar image Eric5h5 · Oct 18, 2011 at 04:57 AM 2
Share

@$$anonymous$$ikbe: perhaps you can point out where I "didn't help". Take your antagonistic attitude elsewhere, please.

avatar image Mikbe · Oct 22, 2011 at 01:23 AM 0
Share

@Eric5h5 Saying "you made a typo" to a novice is just more of the tired old anti-new person attitude rampant in the computer world. If you don't want to help, don't answer.

avatar image Eric5h5 · Oct 22, 2011 at 01:37 AM 0
Share

@$$anonymous$$ikbe: There are two lines of code, and once it's pointed out that's it's just a typo (as opposed to a logic error that needs to be explained), it should be apparent. If I was "anti-new person" then most of my posts here and on forum.unity3d.com wouldn't exist. You're obviously projecting some issues you have onto me; I think you should resolve them elsewhere.

Show more comments
avatar image
0

Answer by aldonaletto · Oct 18, 2011 at 03:48 AM

C# and JS can't see each other during compiling time. If one of them is already compiled, the other can see it (but not the other way around). There exists a predefined order that you can use to determine which scripts compile first (read about this in Script Compilation).
EDITED: OOPS! Your variable declaration is JS too, so forget about this C# rubbish. @Mikbe is right, it's just a typo in the 2nd or 3rd line (one says waterApparatus, the other WaterApparatus). If you place #pragma strict in the first script line, errors like this one will be flagged by the compiler.

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

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

global variable need advice 1 Answer

Global Varible Problem 2 Answers

Global Variables with Prefabs/ Self-Naming Variables 2 Answers

Newbie questions! (Variables and Saving) 2 Answers

Howto access global var from other script? 2 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