- Home /
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);
  } 
}
 
                
              I answered but this site hates my freedom.
Change the third line from Pascal case WaterApparatus to camel case waterApparatus.
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.
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);
   } 
 }
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.
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.
@$$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.
@$$anonymous$$ikbe: perhaps you can point out where I "didn't help". Take your antagonistic attitude elsewhere, please.
@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.
@$$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.
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.
Your answer
 
 
             Follow this Question
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
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                