declaring a variable in function start doesn't work????!!! ERRORS???

function Start() {
static var stopMoving = false;
}

now I can access this variable in other scripts by doing ‘GameController.stopMoving’ but when the variable is in start, I get this error:

BCE004: expecting }, found ‘static’
BCE004: expecting EOF, found ‘}’

but if I put ‘static var stopMoving = false;’ at the top and not inside any function, then I don’t get the error but I only want it to run once on startup so why can’t I put it in start?

BTW: I’m using UnityScript/JavaScript NOT C# :slight_smile:

Why is it static?
Im certain it being static is the issue but I cannot remember why.
Just remove it and tell me how it goes.

EDIT:
Read over the post again.
Instead of static why not make it public and create a reference instead. It wont be as clean if it works but a working solution is better than one that doesn’t.

Same. Why static?

Declaring a static variable in the scope of a funtion does not make sens (at least in C#).

Static means the variable belongs to the class not to the instances. It means that the variable is shared over all objects; changing the value from any object will change it for all objects. Is this you are expecting?

Local scope variables cannot be static or have access modifiers. Simply remove static and things will run.

for static var:

static var stopMoving : boolean;

function Start() {
    stopMoving = false;
}

for public var:

var stopMoving : boolean;

function Start() {
    stopMoving = false;
}

local var:

function Start() {
    var stopMoving : boolean = false;
}