Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

controlp5 behaving differently in setup and draw

$
0
0

Hi all, I have a difficulty with controlp5. I am trying to update the value in a textbox but it won't accept my new string. The code below is my test code to get this working.

In the setup I can pass a string into the .setValue(); and it works but when it comes to the draw I can no longer pass a string into it, it throws an error that says it expects a float.

So the question is why? I can't for the life of me work out why this works then doesn't.

Thanks.

import controlP5.*;

ControlP5 cp5;

String newInput = "boop";

void setup() {
  size(700, 400);

  PFont font = createFont("arial", 20);

  cp5 = new ControlP5(this);

  cp5.addTextfield("Word 1")
    .setPosition(20, 170)
    .setSize(200, 40)
    .setFont(font)
    .setAutoClear(true)
    .setValue(newInput)
    .setColor(255) //text color
    .setColorBackground(0)
    .setCaptionLabel(" ")
    ;

  textFont(font);
}

void draw() {
  background(210);
  newInput = cp5.getController("Word 1").getStringValue();
  cp5.getController("Word 1").setValue(newInput);
  println("NI:" + newInput);
  text(newInput, mouseX, mouseY);
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles