sojamo / controlp5

A gui library for processing.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.plugTo unexpectedly changes plugged variable value

hamoid opened this issue · comments

  println(cfg.opacity); // prints 160

  cp5.addSlider("opacity")
    .plugTo(cfg)
    .setRange(0, 255)
    .setValue(cfg.opacity)
    ;

  println(cfg.opacity); // prints 0

It's not intuitive at all that sending an argument to a function will change that argument.

Current workaround: call .plugTo after .setValue

  println(cfg.opacity); // prints 160

  cp5.addSlider("opacity")
    .setRange(0, 255)
    .setValue(cfg.opacity)
    .plugTo(cfg)
    ;

  println(cfg.opacity); // prints 160

But even better it would be if the .setValue was not required, and just by plugging an object the existing value was read automatically.

Discussion in the Processing forum.

Fixed in dev-2.2.7 branch, thanks for pointing this out.