OSC multiple clients

edited February 2017 in Library Questions

HI,

I'm making a game with 3 computers (1 server en two clients). And when I use the following code i will get an error. And when I remove the float or the int, that one function will work, but when they are both active, it gives an error. I believe it has something to do with the string position, but I have no idea.

the error: ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage to a method in your program. please check your code for any possible errors that might occur in the method where incoming OscMessages are parsed e.g. check for casting errors, possible nullpointers, array overflows ... . method in charge : oscEvent java.lang.reflect.InvocationTargetException

My code:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress pilot, gunner;

int shoot;
float deg;

void setup() {
  size (1000, 1000);

  oscP5 = new OscP5(this,12002);
  pilot = new NetAddress("localhost",12001);
  gunner = new NetAddress("localhost",12000);
}

void oscEvent(OscMessage theOscMessage){
  //print("Received an osc message");
  String msgType =  theOscMessage.addrPattern();

  float degValue = theOscMessage.get(0).floatValue();

  if(msgType.equals("/shoot"))
  {
    int shootValue = theOscMessage.get(0).intValue(); 
    shoot = shootValue; 
  }

  if(msgType.equals("/deg"))
  {

   deg = degValue; 
  }

}

Answers

  • Answer ✓

    Format your code. Press the gear icon to edit your post, then select your code and press ctrl+o. Leave a line above and below your code.

    Your error is very likely due to: float degValue = theOscMessage.get(0).floatValue(); With this line you are assuming all received packages starts with a float value. OSC is complaining because it receive some data that when it tried to extract as a float, it did not work. To avoid this error, and to properly retrieve your data, you need to use addrPattern and typeTag. Please check the examples provided by the library: http://www.sojamo.de/libraries/oscP5/#examples

    Specifically, check http://www.sojamo.de/libraries/oscP5/examples/oscP5parsing/oscP5parsing.pde

    Kf

  • Aah Thanks mate, I figured it out. I just had to put that float degVavlue inside it's respective if statement, just like the int shootValue.

Sign In or Register to comment.