Passing on parameter in a class
in
Contributed Library Questions
•
1 year ago
I'm trying to build an application to send and receive OSC messages. I built a class of buttons and the idea is that if a formatted message ("name"+id+string, such as: name 2 Harrold) is received, the class checks the id and names the buttons accordingly. Unfortunately I get error with this code in the class constructor.
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
Clip clip1;
Clip clip2;
Clip clip3;
Clip clip4;
Clip clip5;
Clip clip6;
Clip clip7;
Clip clip8;
int val=100;
int isplaying;
void setup() {
//size(screenWidth, screenHeight, P2D);
size(500, 500);
PFont font;
font = loadFont("LiGothicMed-48.vlw");
oscP5 = new OscP5(this, 12000);
myRemoteLocation = new NetAddress("127.0.0.1", 11001);
clip1=new Clip(50, 50, color(200), 0);
clip2=new Clip(50, 120, color(255, 232, 160), 1);
clip3=new Clip(50, 190, color(232, 160, 160), 2);
clip4=new Clip(50, 260, color(45, 200, 1), 3);
clip5=new Clip(50, 330, color(145, 200, 221), 4);
clip6=new Clip(50, 400, color(3, 20, 121), 5);
clip7=new Clip(50, 470, color(255, 200, 255), 6);
clip8=new Clip(50, 540, color(200, 160, 145), 7);
}
void draw() {
clip1.display();
clip1.change();
clip2.display();
clip2.change();
clip3.display();
clip3.change();
clip4.display();
clip4.change();
clip5.display();
clip5.change();
clip6.display();
clip6.change();
clip7.display();
clip7.change();
clip8.display();
clip8.change();
}
... and the class:
int b;
color c=255;
int sx=150;
int sy=60;
String clipname="clip";
class Clip {
int x, y;
color cc;
color c;
int id;
Clip(int tempX, int tempY, color tempcc, int tempid) {
x=tempX;
y=tempY;
cc=tempcc;
id=tempid;
}
void display() {
fill(c);
noStroke();
rect(x, y, sx, sy);
//triangle(x+sx, sy, x+sx, y+sy, x+sx+20, y+sy/2);
fill(cc);
rect(x+10, y+10, 130, 40);
fill(0);
text(clipname, x+60, y+30);
}
boolean over() {
if (mouseX>=x&&mouseX<=(x+sx)&&mouseY<=(y+sy)&&mouseY>=y) {
return true;
}
else {
return false;
}
}
void change() {
if (over()&&mousePressed) {
c=100;
OscMessage myMessage = new OscMessage("/on");
myMessage.add(id);
oscP5.send(myMessage, myRemoteLocation);
println(id);
}
else {
c=255;
}
}
void play() {
color d=color(5, 252, 66);
fill(d);
rect(x, y, 10, 60);
}
}
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern("name")==true) {
int nameid = theOscMessage.get(0).intValue();
String named = theOscMessage.get(1).stringValue();
println("name "+nameid+" "+named);
if(nameid==id){
clipname=named;
}
}
}
Where the last bit of the class constructor, with the OSC parsing causes the trouble:
if (theOscMessage.checkAddrPattern("name")==true) {
int nameid = theOscMessage.get(0).intValue();
String named = theOscMessage.get(1).stringValue();
println("name "+nameid+" "+named);
if(nameid==id){ // "Cannot find anything named "id"
clipname=named;
}
Why can't I use int id?
1