JavaScript in MaxForLive: Getting "jsobject 148795" instead of an integer.

Jun 24, 2010 at 1:57am

JavaScript in MaxForLive: Getting "jsobject 148795" instead of an integer.

Hi,

I’m using an object called Report that accumulates information about the live set using LiveAPI objects and then posts it all at once. For some reason, when pushed onto the Report’s list of data, certain integers turn into the string “jsobject” followed by a long meaningless-to-me number.

In the short example below, I’ve created a function f1() that tries to create a Report indicating the track position and folding state of every group track. Track numbers appear correctly, but folding states generate the error described above.

The function f2() is almost identical, but instead of accumulating the data into a Report, it prints the data immediately. f2() does not generate the same problem.

I’m totally confused. Many thanks for your help.
Jeff

function countTracks() {
// Counts the number of tracks in the Live set.
return ( new LiveAPI( this.patcher, “live_set”) )
.get( “tracks” ).length / 2;
}

function Report() {
// A class to accumulate and then post reports
this.data = new Array();
this.clear = function() {
this.data = new Array();
}
this.push = function() {
// adds its arguments, however many they were, to this.data
var args = Array.prototype.slice.call(arguments);
for (var i in args) this.data.push( args[i] );
}
this.post = function() {
post( 0, this.data, “n” );
this.clear();
}
}

function f1() {
// Should post a message, “Groups track N1 state S1 track N2 state S2 “, where N = position on screen, and S = fold state (0 if folded). It alsmost does, except each S, rather than being a 0 or a 1, instead is a “jsobject” string followed by a long meaningless number.
post( “Exceuting f1():n” );
var track;
var report = new Report();
report.push( “Groups” );
for (var i=0; i
track = new LiveAPI( this.patcher, “live_set tracks ” + i);
if ( track.get( “is_foldable” ) > 0 ) {
report.push( “track”, i );
report.push( “state”, track.get(“fold_state”) );
}
}
report.post();
}

function f2() {
// And yet, as this function demonstrates, track.get(“fold_state”) behaves like an ordinary number if I post it immediately, rather than first pushing it onto a Report.
post( “Exceuting f2():n” );
for (var i=0; i
track = new LiveAPI( this.patcher, “live_set tracks ” + i);
if ( track.get( “is_foldable” ) > 0 ) {
post( “track”, i, “n” );
post( “fold_state”, track.get(“fold_state”), “n” );
}
}
}

#51020
Jun 24, 2010 at 9:20am

I don’t have M4L so I can’t be sure but it looks like track.get(“fold_state”) returns an array. Test this with typeof() to see if it is a number or an object. When you print to the max window arrays are only unfolded to one level, so an array within an array will print as: “1 2 3 jsobject 1469037 7 8 9″ instead of “1 2 3 4 5 6 7 8 9″, for example. You should try either [0] to read the firt element or maybe parseInt() to force it to a number.

lh

#183054

You must be logged in to reply to this topic.