General
switching scripts on and off
Started by auralsculpture on .
Sign in or create an account to join the conversation.
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
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
Have you tried using if in your script?
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}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 ...
if(Switches.x==1){Multiball.y=(accelerometer[0]*-1+1)/2};
something wrong, I'm guessing it needs to be in one line ...
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:
if (Switches.x == 1) {
Multiball.x = (accelerometer[1] + 1) / 2;
Multiball.y = (1 - accelerometer[0]) / 2;
}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.
acceltester.jzlib.zip
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.
acceltester.jzlib.zip
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.
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??
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??
well that's what the if() is used for it turns off the fonctionality of the script 