- Home /
Need some help with my Gravity Gun, New to Scripting.
Hi, I'm having trouble with static variables, I dont know why because I think I'm doing it right, maybe it's not the way I wrote the Variable, maybe it's the way the first code it written which two people helped me with. I'm trying to create a Gravity Gun, so I have a Standby script which is placed on the Gun it's self, then I have an Object script, the object script makes whatever it's attached to follow the reticule on the gravity gun.
Here's the Error I'm receiving BCE0005: Unknown identifier: 'Activate'.
if(Activate==true){
//do something
}
This is in the Object Script right before the function Update.
static var Activate = false;
This is in the Standby Script at the top.
Here's what I'm trying to achieve, the Static var is what's used to activate the function command inside the object script so it activates the script and it will follow the Gravity Gun's reticule, the Static var is inside the Standby Script it is set to "false" as default, then it gets changedwhen I press the Left Mouse Button, it's Supposed to change to static var Activate = true;
Here's the standby script.
static var Activate = false;
function Update () {
}
if( Input.GetButtonDown("Fire1"))
{
//I'm also thinking about what I need to put here as It wont allow me to use the Variable inside here, I've tried (Activate==true);
but I get the Error BCE0034: Expressions in statements must only be executed for their side-effects.
}
Please dont redo the Entire code, I dont want to go through all the hassle, I just want to help me sort out these errors. I'm getting used to scripting, I'm learning where to put lines of codes now, I just need a bit more practice before I can consider myself "Good" at programming. Please read and go over everything, I'll post both scripts if nessasary. Thanks for reading and contribution.
Explain exactly what a gravity gun is, because some people might not know that. Is it a gun that increases gravity of it's target, or what?
You need to pull back from the problems - these things are not solved by trying to look at individual lines and individual error messages. A compiler gets to think like that, but you as a programmer have to understand the root cause of the error, which may have resulted from a mistake somewhere else entirely. When you program, you must understand the entirety of what you have written and why it should function in the way you anticipate. All the compiler can do is tell you when it cannot understand you, but you then have to go and fix your code, be the change some little syntax error on the specified line, or a semantic error that could be anywhere related to that line.
Currently, you do not understand your "own" code, and so you cannot understand the compiler's complaints.
You must go back and understand your code, otherwise you're just getting other people to write code for you, which will never get you to being any sort of programmer, good or otherwise.
Sorry nighthawx349, I dont know why I didn't explain it, It's a gun that can manipulate Physical Objects.
Thanks Warwick Allision, You made me understand how the Compiler works.
Answer by aldonaletto · Sep 02, 2011 at 01:59 AM
Man, your question is really confusing! What I understood from your question is that you want to set the variable Activate to true when the mouse left button is pressed, and this variable will be used in other scripts. Supposing I'm right, the Standby.js script should be something like this:
static var Activate = false;
function Update(){ if (Input.GetButtonDown("Fire1")){ Activate = true; } } Since Activate is static, you can access it in other scripts as Standby.Activate:
if (Standby.Activate){ // you don't need to compare a boolean to true // do something }
Thanks, This Helped alot, I know know how to use Variables with If statements :)
Your answer
Follow this Question
Related Questions
List in JS, Unknown indentifier 3 Answers
BCE0005 Unknown identifier issue 1 Answer
shooting script error (java) 2 Answers
Exception error 1 Answer