hi sr.richie -
your suspicions are correct. when you declare a new controller, you give it a name, and controlP5 "magically" - that is, using the java reflection API - accesses the code you're actually writing to tell it about the event.
there are three ways to access information about "events" such as moving a slider.
1.) when you name a slider "mrSlider" in the addSlider method, then create a method "void mrSlider( float theAmt )" or "mrSlider( int theAmt )", that method will be called each time the slider generates an event detected by the library.
2.) controlp5 has the additional ability to update a public variable, so, using the previous example of a slider named "mrSlider", you could declare a variable outside of a method named "public int mrSlider" or "public float mrSlider", and that variable will have the updated value stored in it, bypassing the event notification, but assuring that the variable has the latest value in it.
3.) you can declare a method "void controlEvent( ControlEvent theEvent )", which gives you access to all the information associated with
every event, such as the event generator's name, the event generator's label, the event generator's value, and the event generator's id number, if it has one. this last option is the "heavyweight" way to handle events - the most complex and is clogged with the most information. see the api for more information about methods that can be called on a ControlEvent object.
Quote:import controlP5.*;
ControlP5 controlP5;
int myColorBackground = color(0,0,0);
int sliderValue = 100;
void setup() {
size(400,400);
controlP5 = new ControlP5(this);
Slider s = controlP5.addSlider("slider",100,167,128,100,160,10,100);
s = controlP5.addSlider("sliderValue",0,255,128,200,200,10,100);
}
void draw() {
background(myColorBackground);
fill(sliderValue);
rect(0,0,width,100);
}
void slider(float theColor) {
myColorBackground = color(theColor);
println("a slider event. setting background to "+theColor);
}