Forums > Javascript

Stupid problem

January 11, 2010 | 2:55 pm

Hi.
I’m realy sorry to post that problem because I know that’s very simple but I don’t see my mistake.
This script is just to stop a constant seeding of value to a changement of statut.

Here it is :
//entrée et sortie
inlets = 1;
outlets = 1;
//initation variable
var sortie = 0;
//démarrage de la convertion
if (inlets == 1) {
if (sortie == 0) {
sortie = 1;
}
}
else if (sortie == 1) {
sortie = 0;
}
post (sortie);


January 11, 2010 | 3:06 pm

I’m not entirely sure what you’re trying to achieve. It looks like you’re just trying to swap the value of the sortie variable between 0 and 1 each time this code is called. What are you expecting to be printed to the max window each time and what values are you actually receiving?

A more efficient way to switch sortie each time would be:

sortie = 1-sortie;

lh


January 11, 2010 | 3:12 pm

or

sortie = !sortie;


//start js
sortie = 0;
function bang(){
sortie = !sortie;
post(sortie);
}
//end js


January 11, 2010 | 4:58 pm

First off, you probably need to define some function(s). The global code is only read once when the js object is instantiated. Then you might consider using the !- 1 (or == 0) object ;-)


January 11, 2010 | 6:55 pm

Well i’m going to explain what i’m doing.

I do a trigger audio (with a mic input, the user put a threshold like fore a noise gate. When it goes over threshold, a sample choose by the user is playing) in Ableton Live for my final work at school.
For now, I have a noise gate who gives information about the statut (0=no sound and & 1=sound passed thrue the gate).

But it gives EVERYTIME statut but I just want to have the "impulsion" of the changement value. "One" will be the moment to play the sample.

I was sure that will be more easer in JS with a variable who will only change when the entrance value is different of him value.

Correct me if I’m wrong of course, I’m here to finish my school project of course :)


January 11, 2010 | 8:14 pm

You might be looking for the change object. Here’s a simple example (you might want to add a few more things to smooth the signal).

– Pasted Max Patch, click to expand. –

January 11, 2010 | 9:06 pm

Thanks man !!!
It do exactly the thing that I want !


Viewing 7 posts - 1 through 7 (of 7 total)