oscP5listener, objects, and arrays!

Hi all,

I'm trying to tidy up a sketch using arrays, in one instance to call multiples of an object, 'SoundObject.' Each object receives data over oscP5. My understanding is that for classes to function with oscP5, you need to declare a 'listener' for each object.

SoundObject[] objects = new SoundObject[7];

void setup() {

for(int i = 1; i < objects.length; i++) { 
  String x = "/xpos"+i; //unique tags for each instance of class
  String y = "/ypos"+i;
  String z = "/zpos"+i;
  String a = "/amp"+i;
  objects[i] = new SoundObject(x, y, z, a, width/2, height/2, 500, 100);
  oscP5.addListener(objects[i]); //Doesn't seem to work?
  objects[i].id = i;

In this code, 'oscP5.addListener(objects[i]);' flags a NullPointerException. Is what I am trying to do even possible? Does the oscP5 library support this approach?

Cheers in advance!



Sign In or Register to comment.