[javascript-dev] Storing Maxobj in an Array
David Rowland
david.rowland at uwe.ac.uk
Tue Mar 25 15:40:40 MDT 2008
- Previous message: [javascript-dev] Re: BUG: javascript can't handle large pattrstorage clientlist when overdrive is enabled
- Next message: [javascript-dev] Re: Storing Maxobj in an Array
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi all, I'm quite new to Javascript so am learning as I go along but I can't find any reason why what I'm trying to do wont work.
I basically have a load of patches that form synthesizer modules and am writing a Javascript file which will control their creation, placement, connections and removal.
I have come as far as creating some units using 'bpatchers' and simply connecting them in the script but as there may be many instances of one patch I need to keep track of them.
What I am trying to do is create an array to store the 'Maxobj' object returned from the 'newobject' 'patcher' method. When I use a standard variable the code works fine but when I try to access properties of the 'Maxobj' stored as an array element I get the error:
• error: js: Unit Handler.js: Javascript TypeError: OSCUnit[noOSCUnits] has no properties, line 22
Here is my code so far. Note I have only implimented the array system in the "OSC Unit" case for testing purposes.
autowatch = 1; //Recompile script on save
editfontsize = 10; //Make the font in the text editing window 10pt
//Global Variables
//These are used to keep track of what units are present in the patcher and how they are created
//Arrays to hold created units
var OSCUnit = new Array();
//Variables to keep track of how many units have been created
var noOSCUnits = 0;
var noOSCFilterUnits = 0;
function create(input)
{
switch(input)
{
case "OSC Unit":
OSCUnit[noOSCUnits] = patcher.newobject("bpatcher", 300, 100, 300, 100, -220, -30, "OSC Unit.pat", 0); //Create new OSC Unit
OSCUnit[noOSCUnits].varname = "OSC"; //Name new unit 'OSC'
noOSCUnits ++; //Incriment the 'noOSCUnits' variable
OSCUnit[noOSCUnits].varname = OSCUnit[noOSCUnits].varname + noOSCUnits; //Concatenate the name and the number of units
break;
case "OSC Filter Unit":
OSCFilterUnit = patcher.newobject("bpatcher", 300, 200, 300, 200, -190, -50, "OSC Filter.pat", 0); //Create ne OSC Filter Unit
OSCFilterUnit.varname = "OSCFilter"; //Name new unit 'OSCFilter'
noOSCFilterUnits ++; //Incriment the 'noOSCFilterUnits' variable
OSCFilterUnit.varname = OSCFilterUnit.varname + noOSCFilterUnits; //Concatenate the name and the number of units
patcher.hiddenconnect(OSCUnit, 0, OSCFilterUnit, 0);
break;
default:
post("No unit selected");
break;
}
}
Hope someone can help me solve this problem as it's the basis of degree dissertation.
Cheers, Dave.
- Previous message: [javascript-dev] Re: BUG: javascript can't handle large pattrstorage clientlist when overdrive is enabled
- Next message: [javascript-dev] Re: Storing Maxobj in an Array
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
