Page 1 of 1

switching scripts on and off

Posted: 05 Jan 2012 22:40
by auralsculpture
I have a script on an object for using the accelerometer action()

I'd like to turn this on and off with a switch, but as the script is not an "attribute" as such I can't figure out how

Cheers
Colin

Re: switching scripts on and off

Posted: 06 Jan 2012 01:19
by lucasparis
Have you tried using if in your script?

Code: Select all

if(cond.x==1){Fader2.x=x};
cond would be the name of the switch to turn on and off the accelerometer and you would put your accelerometer stuff inside the {curly brackets}

Re: switching scripts on and off

Posted: 06 Jan 2012 04:07
by auralsculpture
if(Switches.x==1){Multiball.x=(accelerometer[1]+1)/2)};
if(Switches.x==1){Multiball.y=(accelerometer[0]*-1+1)/2};

something wrong, I'm guessing it needs to be in one line ...

Re: switching scripts on and off

Posted: 06 Jan 2012 04:31
by highmountain
The whitespace is not important, except for readability. What you wrote works if you change "};" to ";}" and remove the extra ) on the first line. But I'd recommend formatting it in an easier to read way, so that it is easier to make changes:

Code: Select all

if (Switches.x == 1) {
     Multiball.x = (accelerometer[1] + 1) / 2;
     Multiball.y = (1 - accelerometer[0]) / 2;
}

Re: switching scripts on and off

Posted: 06 Jan 2012 04:58
by auralsculpture
OK I think I understand the syntax for curlies better now.

doesn't work though ... I have attached the module

I got the accelerometer code from another module in the library, and it is sitting in the Multiball structure as action() with the current material named off() - wish you could rename a script ...

Ultimately I want to use this module as a controller for filter and resonance on the x and y, but to be able to easily switch between finger only and accel control. Plus I'm trying to teach myself some more scripting techniques

Thanks for your help so far.

Re: switching scripts on and off

Posted: 06 Jan 2012 05:07
by highmountain
The file you posted works. I think you may get more what you are expecting if you change the execution type to "On Frame." "On expression" is only executed when the value of the expression changes, so your script only captures the value of the accelerometer at the moment the switch is activated. "On Frame" is executed every frame, which means 60 times per second no ifs ands or buts, so changing the execution type to that will result in continuous updates whenever the switch is active.

Re: switching scripts on and off

Posted: 06 Jan 2012 05:58
by auralsculpture
Ha Ha! you beauty!

The scripting really isn't covered enough in the manual, we need some tutorials. Maybe I'll write one for this.

Next to figure out the gyro ...

The first question I posed is still relevant though ... is there a way to switch a script or variable on and off??

Re: switching scripts on and off

Posted: 07 Jan 2012 03:35
by lucasparis
well that's what the if() is used for it turns off the fonctionality of the script ;)