JavaScript is object-oriented programming. That means it has properties and methods.
Start by specifying "inlets = " and "outlets = " properties.
function name(1,2,3) {
method();
method();
}
A function can have arguments. Above, 1,2, and 3 are arguments.
Useful method in Max: outlet(1, "bang");--this will send out the outlet on the right, whereas outlet(0) sends out the left outlet--try to keep right-to-left order as is typical for Max.
function anything() {
This means, if anything comes in other than what's already defined, do this.
A function can call another function within it.
In JS, no distinction between ints and floats. In Max, yes.
At beginning of script, set variables. In JS, equals sign means "set this to this." A double equals sign == means is it equal to? Testing if the logical expression is true or false.
var x = 0;
Any variable you set outside of a function is considered a global variable. That means it's accessible from any part of the program, but that doesn't mean it can't be changed in a function. A local variable only exists within a function, and it ceases to exist after that.
Set up script so if people put the wrong things into the object, sends out an error message--can do this function-by-function.
function msg_int( incoming) {
That's a function that allows an integer to be input, can set that to a variable to store it, and/or can send it out immediately.
A function in a JS script is a potential incoming message from Max. So you might have function msg_int, or function msg_float, or whatever other message might come in.
isNaN means "is not a number"--so if incoming isn't a number, can send an error, or whatever
Arrays:
thearray = new Array(1);
array name = new Array(# of arguments);
myfavoritearray = [32, 76, 95.3, "chris"];
Very much like a coll object, numbered automatically with index numbers
while loop-->set an initial condition, keep testing condition, if it's this, do this--have to also set a stop condition
No comments:
Post a Comment