[javascript-dev] Re: Storing Maxobj in an Array
John Pitcairn
cycling74forum at opuslocus.net
Tue Mar 25 16:13:30 MDT 2008
- Previous message: [javascript-dev] Storing Maxobj in an Array
- Next message: [javascript-dev] Re: Storing Maxobj in an Array
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Quote: Dave wrote on Wed, 26 March 2008 09:40
----------------------------------------------------
>OSCUnit[noOSCUnits].varname = "OSC"; noOSCUnits ++; OSCUnit[noOSCUnits].varname = OSCUnit[noOSCUnits].varname + noOSCUnits;
You're incrementing noOSCUnits then attempting to use that as an array index, when that array element doesn't exist. The third line above is trying to use OSCUnit[1] when there is only 1 item in the array, OSCUnit[0].
But you should also be testing that you're actually getting an OSCUnit object created, and that manually-incremented noOSCUnits counter seems a little prone to trouble too, when OSCUnit.length or OSCUnit.push (to add an item) gives you the array size directly. So, assuming you want OSCUnit[0] to be named "OSC1":
if(obj = patcher.newobject("bpatcher", 300, 100, 300, 100, -220, -30, "OSC Unit.pat", 0)) {
noOSCUnits = OSCUnit.push(obj); // 1
obj.varname = "OSC" + noOSCUnits; // "OSC1"
// note obj and OSCUnit[0] still refer to the same object
}
else {
post("error: no OSCUnit returned");
}
- Previous message: [javascript-dev] Storing Maxobj in an Array
- Next message: [javascript-dev] Re: Storing Maxobj in an Array
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
