Trying to access a variable from a different script.

Hi all,
I have a script (Controller.js) on 2 rigid bodies that adds force based on the accelerometer input. I have another script (InfoButton.js) on the camera that displays sliders. The sliders control the value of my variable (a) in the InfoButton script.

I need to access that variable in my Controller script so I can globally scale down the force that is added to the rigid bodies.

I’m new to Java scripting and this is turning into a pretty big roadblock for me. So, please excuse my noobness, but any help would be greatly appreciated.

Thanks!

Welcome aboard !!

You are basically trying to “register” objects with a “manager”. There’s a bunch of ways. Here is one, non-procedural method…

  1. in your Controller.js
    var infoButton[ ] : InfoButton;

  2. drag all the objects that have InfoButton.js onto the infoButton array. You now have registered all your rigid bodies!

3.in your Controller.js, call some function like this:
var i = 0;
infoButton*.UseTheForce(20.f);*
hth - I am not at my pc to actually test (and I’m a C# guy). Have fun!

try using static variables:

in InfoButton.js:

static var a : int = 0;

in Controller.js:

var controllerVariable : int = InfoButton.a;

Thanks dudes! I really appreciate it.