x


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.

more ▼

asked Sep 01, 2011 at 11:56 PM

Dryden Richardson gravatar image

Dryden Richardson
135 110 91 91

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?

Sep 02, 2011 at 12:01 AM Overlord

Sorry nighthawx349, I dont know why I didn't explain it, It's a gun that can manipulate Physical Objects.

Sep 02, 2011 at 07:58 PM Dryden Richardson

Thanks Warwick Allision, You made me understand how the Compiler works.

Sep 02, 2011 at 07:59 PM Dryden Richardson

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.

Sep 02, 2011 at 01:11 AM Waz
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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
}
more ▼

answered Sep 02, 2011 at 01:59 AM

aldonaletto gravatar image

aldonaletto
57.6k 33 91 301

Thanks, This Helped alot, I know know how to use Variables with If statements :)

Sep 02, 2011 at 07:57 PM Dryden Richardson
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x6257
x3606
x77
x10

asked: Sep 01, 2011 at 11:56 PM

Seen: 1305 times

Last Updated: Sep 02, 2011 at 08:00 PM