About Local and global variables

 import controlP5.*;
 ControlP5 cp5;
 RadioButton r1, r2;
 void setup() {
 size(700,400);
  
 cp5 = new ControlP5(this);
 r1 = cp5.addRadioButton("radioButton")
         .setPosition(100,180)
         .setSize(40,20)
         .setSpacingColumn(50)
         .addItem("Start",1);    
}
public static void radioButton(int a) {
  println(a);
}

 void draw() {
if(a==1){
  println("Hello");
}
}

where is the problem in this code

@glv

1 Like

https://processing.org/examples/variablescope.html

:)

2 Likes

a is only known inside the function radioButton

You could

  • make a global variable (declaration before setup ()) named statusButton and
  • in function radioButton say statusButton = a;

Then in draw check if(statusButton == 1) …

4 Likes