bad outlet index 0 problem
Hi there, tried to find an answer to this on the forum already but no luck. I get the following error message - "js: bad outlet index 0", When I run this code:
///////////////
inlets = 1;
outlets = 2;
var mymatrix = new JitterMatrix(4, "char", 320, 240);
f = new Folder("slideShow/images");
fileArray = new Array();
var player = new JitterObject("jit.qt.movie", 320, 240);
init();
function init() {
while (!f.end) {
fileArray.push(f.filename);
f.next();
}
var fileNum = f.count;
outlet(0, fileNum);
}
function bang() {
player.matrixcalc(mymatrix, mymatrix);
outlet(1, "jit_matrix", mymatrix.name);
}
function msg_int(a) {
player.read(fileArray[a]);
var handler = player.duration;
post(handler);
post();
}
////////
Doesn't seem to be a problem if I nest the"var fileNum = f.count; outlet(0, fileNum);" bit within the bang function, but if it's in an init() function or unnested it brings up the error. Unfortunately I only want it to output this information once, at the beginning of the program, so I can't leave it in the bang function. It's probably very obvious, but I'm pretty new to this javascript stuff...
Thanks in advance.
hi geckohooks,
you call init()
in your global scope. That can lead to the situation that your outlets are not yet initialized.
If you need to to a basic setup of your js object user the loadbang()
function.
This one is called after the patch is loaded entirely.
id' recomment :
// declare variables in global scope
var mymatrix;
var f;
var fileArray;
var player;
function loadbang() {
//assign them after everything is loaded
mymatrix = new JitterMatrix(4, "char", 320, 240);
f = new Folder("slideShow/images");
fileArray = new Array();
player = new JitterObject("jit.qt.movie", 320, 240);
// then call your initiation routine
init();
}
Fantastic! That's sorted it out. I kept thinking it was because the images hadn't had time to load, I hadn't thought that the outlets might not be ready!
I presume then that the loadbang() function is the equivalent to the loadbang object in max -- which I guess means that it triggers itself; and doesn't need a loadbang object sent to one of the js objects inlets. But does the loadbang function only trigger once all objects are initialised? Or once everything within the js object is initialised?
Anyway - thanks so much. And thanks for the quick reply.
you're right. the loadbang()
function works as JavaScript representation of the loadbang object. It is not triggered when the [js] is instantiated but when the patch is loaded.
That means if you would dynamically (i.e. with scripting through [thispather] add an instance of your [js] loadbang()
would not be called.
j.