controlP5 problem.

edited July 2018 in Library Questions

hello!

I`ve a problem with controlP5 library. In a json file i stored the value of a variable of a class name "layer", witch is equal to buttonBar choice.

buttonBar = layer

Next, i want to load that value, but i cant make that buttonBar set the value and display on... the same is happening with a listBox.

but no with sliders: this works perfectly. (t2) is a slider.

      float T2 = shader.getFloat("t2"); // value load from  JSON file
      shaderWin.cpp5.getController("t2").setValue(T2);

but this not:

    int n = numberLayer.getInt("numberLayer");
    shaderWin.cpp5.getController("l").setValue(n); // "l"  is a buttonBar. i want the item number N on.



    cpp5.addButtonBar("l")
      .setPosition(0, 0)
      .setFont(font)
      //.setSize(1000, 20)
      .setWidth(900)
      .setColorBackground(0)
      .addItems(split("0 1 2 3 4 5 6 7 8", " "))
      ;

  void l(int n) {
    println("bar clicked, item-value:", n);
    layer.layer = n;
  }


anybody know why?

Answers

  • There is a new forum

    Please ask there

  • I didn't test your code not I attempt running it. First, you should avoid naming your controllers as just numbers. It is not a good practice in short. I also suggest to try shaderWin.cpp5.getController("l").setValue(float(n)); as it seems the first setter was working for you.

    Finally, where are you setting this value? Are you doing it either in setup, draw, any of controlP5 callback functions or any other function that are called inside any of the aforementioned functions? In other words, you are not calling your setter in a global scope, right? I have to ask as this is not clear in your post.

    Kf

Sign In or Register to comment.