no valid object set? JS/Max For Live

Kirkwood West's icon

I'm doing some JS/Max4live stuff and keep seeing this message come up in green in the max console.

get: no valid object set
call create_clip 1: no valid object set
get: no valid object set

Code seems to be executing properly and working as expected. Are these asserts/warnings? Should I be concerned?

var trackNum = 0;
sceneNum = 4;
var path = "live_set tracks " + trackNum + " clip_slots " + sceneNum;
var clipslotObj = new LiveAPI(path);
var clipSlotHasClip = clipSlotObj.get('has_clip');

Even when i log clipSlotHasClip it is valid. So i'm not sure what the warning actually is. Any Ideas?

Valery_Kondakoff's icon

I'm pretty sure this is an initialisation issue. You call LiveAPI in the global section of js-file. This means, the code is executed exactly after js-object instantiation, but not necessarily the entire amid-device was initialised.

Try this:

tyler mazaika's icon

Doesn’t the constructor for LiveAPI take a callback as the first argument and the path as the second?

Kirkwood West's icon

You call LiveAPI in the global section of js-file.

Thanks for your reply Varlery. I broke the script out of a function so I could paste it in the board. I have this function set up so when I press a button it does the call. So the API should be instantiated at this point. BUT yI will double check this.

I'm eyeing your screenshot and I'm also wondering how you have your external editor(visual studio) set up for .js files? Specifically... are you able to get the max library working for auto-complete? or js internals?

Doesn’t the constructor for LiveAPI take a callback as the first argument and the path as the second?

Yeah, I'm not sure about this! But it looks like you are right.. this is the range of stuff i've seen online.

api = new LiveAPI(this.patcher, "live_set");
api = new LiveAPI(this, "live_set");
api = new LiveAPI("live_set");
api = new LiveAPI(function_callback, "live_set");

Not sure what is correct... also what if you are using the live API inside of a prototype constructor... then using "this" would have a whole new meaning.

tyler mazaika's icon

If you don't need a callback function (because you aren't observing anything) I normally just go with:

var api = new LiveAPI(null, "live_set")

This is also happily immune to the scope confusions inside of objects/functions.

My normal solution for separating "this" as a reference to my own JS classes and the "this.patcher" context is to have a separate function outside of my objects:

function thispatcher() { return this.patcher }

Calling thispatcher() from inside my classes still returns the Patcher object.

And just for the sake of completeness... to have an observed property+callback within your own JS class, you can pass your object's "this" context into a your callback explicitly using <method>.call(). Otherwise the default 'this' in the callback context is of the LiveAPI object, not your object's (and also not the Patcher's).

function MyClass() {
    var obj_context = this
    this.api_observer = new LiveAPI( function(){
obj_context.my_callback.call(obj_context) }, "live_set")

MyClass.prototype.my_callback = function(first_argument) {
// callback code

};

Passing "this" directly as the callback function to a LiveAPI constructor seems like a mistake.

HTH,
Tyler

Kirkwood West's icon

Thats sick Tyler! Super Hero. Thank you for that extra tidbit.

tyler mazaika's icon

You're most welcome, Kirkwood. :-)

Valery_Kondakoff's icon

I'm eyeing your screenshot and I'm also wondering how you have your external editor(visual studio) set up for .js files? Specifically... are you able to get the max library working for auto-complete? or js internals?

No, as far as I know, there is no Max-specific autocompletion currently available for VSCode.

Myer Nore's icon

I'm getting some Max-specific autocompletion in VSCode using https://github.com/zsteinkamp/m4l-typescript-base.