switching scripts on and off
-
- Newbie
- Posts: 33
- Joined: 22 Dec 2011 12:18
switching scripts on and off
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
-
- Newbie
- Posts: 30
- Joined: 23 Dec 2011 20:15
Re: switching scripts on and off
Have you tried using if in your script?
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}
Code: Select all
if(cond.x==1){Fader2.x=x};
-
- Newbie
- Posts: 33
- Joined: 22 Dec 2011 12:18
Re: switching scripts on and off
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 ...
-
- Newbie
- Posts: 21
- Joined: 13 Dec 2011 05:52
Re: switching scripts on and off
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;
}
-
- Newbie
- Posts: 33
- Joined: 22 Dec 2011 12:18
Re: switching scripts on and off
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.
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.
- Attachments
-
- acceltester.jzlib.zip
- (1.07 KiB) Downloaded 112 times
-
- Newbie
- Posts: 21
- Joined: 13 Dec 2011 05:52
Re: switching scripts on and off
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.
-
- Newbie
- Posts: 33
- Joined: 22 Dec 2011 12:18
Re: switching scripts on and off
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??
-
- Newbie
- Posts: 30
- Joined: 23 Dec 2011 20:15
Re: switching scripts on and off
well that's what the if() is used for it turns off the fonctionality of the script