We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › ControlP5 setValue
Page Index Toggle Pages: 1
ControlP5 setValue (Read 989 times)
ControlP5 setValue
Jun 26th, 2009, 9:35pm
 
Hi everyone.

I've been having some problems with ControlP5 library, and i'm unable to find any "easy" soluction.

My problem is that every time i set a value to a button (and probably any other simple interface) fires an event. That means that every time i do button.setvalue( value ), i get the same event as the button was pressed.

This is a very big problem for me, because that's the last thing i want to happen on the situation i have on my program.

My question is:
Is it possible to change the button value without triggering the event?

Here goes a small bit of code that shows exactly my problem.

Code:
import controlP5.*;

ControlP5 controlP5;
controlP5.Button bb;

int myColorBackground = color(0,0,0);

int buttonValue = 1;

void setup() {
 size(100,100);
 controlP5 = new ControlP5(this);
 bb = controlP5.addButton("button",10,10,10,80,20);
 bb.setId(1);
}
 
void draw() {
 background(buttonValue*10);
 bb.setValue(0);
}

void controlEvent(ControlEvent theEvent) {
 println(theEvent.controller().id());
}


void button(float theValue) {
 println("a button event. "+theValue);
}
Re: ControlP5 setValue
Reply #1 - Jun 30th, 2009, 7:07am
 
hi there,
you can disable a controller from calling a method by using the setBroadcast() method of a controller, e.g.
Code:

bb.setBroadcast(false);

setting the broadcast flag of a controller to false allows you to set the value in your code without having to call any method linked to the controller in your program. but at the same time you will not be able to trigger an event when pressing the button with the mouse if the broadcast is set to false. what you can do in your case is:
Code:

void draw() {
background(buttonValue*10);
// disable the broadcasting of values
bb.setBroadcast(false);
// set the value of bb, neither controlEvent() nor button() is called
bb.setValue(0);
// reset the broadcast behavior of bb so that an event
// will be triggered when bb is released.
bb.setBroadcast(true);
}


Page Index Toggle Pages: 1