Listen to ofParameter<bool> in B class from A class

Hello,

I have class B in which i have an ofParameter (used as ofxGui toggle button)
From class A i would like to listen for the class B parameter change.

B_Object.theParameter.addListener(&B_Object, &ofApp::onEventFunction);

It throws an error on compilation :

 no Matching function for call to ofAddListener

it should be something like:

B_Object.theParameter.addListener(&this, &ofApp::onEventFunction);

if the listener is a function of ofApp if it’s of another object:

B_Object.theParameter.addListener(&A_object, &AClass::onEventFunction);

the first parameter of addListener is the listener object and the second the listener method in that object’s class

ok thanks for the answer.

does the ofParameter event is thrown at every affectation or only when value changes ?

for instance, i have

theParameter = true;

if i do set it to true again, event is thrown. I expected it would be thrown again only when switching to false.

no, it’s called every time the value is set no matter the value since certain types might not implement !=. For example you could have an ofParameter<ofPixels> which can’t be compared for inequality.

ok ! so how would you change a value once ?

check the value before setting it?

instead of:

theParameter = true;
if(theParameter != newValue){
    theParameter = newValue;
}

well… i should have thought about it…
brain issue :slight_smile:

thanks a lot