I have six toggles: I, II, III, IV, V, VI. If toggle I is true, it changes the variable cycleNumber to 1. If toggle II is true, it changes the variable cycleNumber, and so on. However, at the moment, if I click toggle I, it becomes true and cycleNumber changes to 1, but if I were to then click toggle II, cycleNumber changes to 2, but toggle I still remains true, etc.
Basically I want to create a menu that if an element was clicked, it would have an active state until another element is clicked in the menu which I couldn't figure out how to get to work with a button from the ControlP5 library.
Here's the code I'm currently using:
import controlP5.*;
ControlP5 cp52;
int cycleNumber = 0;
void setup() {
cp52 = new ControlP5(this);
ControlFont cf24 = new ControlFont(createFont("Arial",24));
cp52.setControlFont(cf24);
cp52.setColorForeground(color(230));
cp52.setColorBackground(color(215));
cp52.setColorLabel(linkColor);
cp52.setColorActive(color(255));
for(int i=0; i<6; i++) {
int w; if(i==0) { w=15; } else if(i==1) { w=23; } else if(i==4) { w=25; } else { w=30; };
Toggle t = cp52.addToggle(cycleButtons[i], false, i*80+125, 67, w, 20);
t.setLabel(cycleButtons[i]);
controlP5.Label l = t.captionLabel();
l.style().marginTop = -28; //move upwards (relative to button size)
l.style().marginLeft = 4; //move to the right
}
}
void draw() {
// Other stuff....
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isController()) {
if(theEvent.controller().name()=="I") {
if(theEvent.controller().value()==1) { cycleNumber = 1; } else { cycleNumber = 0; }
}
if(theEvent.controller().name()=="II") {
if(theEvent.controller().value()==1) { cycleNumber = 2; } else { cycleNumber = 0; }
}
if(theEvent.controller().name()=="III") {
if(theEvent.controller().value()==1) { cycleNumber = 3; } else { cycleNumber = 0; }
}
if(theEvent.controller().name()=="IV") {
if(theEvent.controller().value()==1) { cycleNumber = 4; } else { cycleNumber = 0; }
}
if(theEvent.controller().name()=="V") {
if(theEvent.controller().value()==1) { cycleNumber = 5; } else { cycleNumber = 0; }
}
if(theEvent.controller().name()=="VI") {
if(theEvent.controller().value()==1) { cycleNumber = 6; } else { cycleNumber = 0; }
}
}
}
Thanks in advance!!!