Forums > Javascript

Best way to use msg_float()?

June 1, 2014 | 10:07 am

I have a JS object with multiple inlets. Two of them are intended to respond to floats. These two will then process the float differently.

Full disclosure, I’m still new to Javascript. Anyway, I know I can use a function declaration of msg_float and then set up a switch inside of it:

function msg_float(x) {
	switch(inlet) {
		case 0:
		// stuff 1
		break;
		
		case 1:
		// stuff 2
		break;
	}
}

Is this the best way to do this? I was trying to figure out how to use msg_float as an inner-function but I couldn’t do so. I possibly couldn’t do so due to a scope issue. How do others go about processing lots of incoming data through Javascript?


June 1, 2014 | 10:56 am

Yes, I’d say that’s the best approach.


June 1, 2014 | 11:27 am

Cool. Thanks for your opinion. I’m studying JS alongside Max and so I’m trying to implement effective JS practices whenever it’s feasible. If this is the best way, then alright. Thanks.


June 1, 2014 | 5:32 pm

If you’re going to use plain numbers as input, it’s pretty much the only way. Of course, if you have only one inlet, the switch is not necessary. And if you have only two inlets, a simple "if (inlet==1) {} else {}" construct will do. The other way to roll is to use only one inlet, but use selectors other than "float", such as "tempo 120." and then have a tempo(t){} function.


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