We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Learning ControlP5 a bit painful but that's OK except for occasional puzzles such as:
In CP5 examples the creation of a toggle control is this:
cp5.addToggle("toggle")
.setPosition(40,250)
.setSize(50,20)
.setValue(true)
.setMode(ControlP5.SWITCH)
;
This generates not only the default coloration (black/blue) but places the "toggle" characters in all-caps below the graphic. My nearly-identical code is this:
cp5.addToggle("run-pause")
.setPosition(900, 50)
.setSize(50, 40)
.setValue(true)
.setMode(ControlP5.SWITCH)
;
It creates the expected blue/black widget but no "RUN-PAUSE" text below the control. Why? Sure, I can add a text label and would do so to provide better captions for certain controls but it's still a puzzle.
Answers
Further: I've found the additional parameter ".setCaptionLabel("text")" and I can initialize the text under the toggle graphic to "Running" -- although I'm not fond of all-caps. The next step is the event handler to respond to the toggle click: change Running to Paused while issuing the appropriate loop() or noLoop() commands. (I'm interrupting the draw() cycle.)
That is, what goes into the annotated lines below?
I know I'm confused as to what object the setCaptionLabel() method is attached. But a couple of wild guesses haven't worked.
OK, fixed it myself. Created Toggle variable and set it to the Toggle returned from the cp5.addToggle("runPause") call during setup(). This in setup():
The code (outside the draw() loop) associated with the toggle widget is this:
Hope this helps someone else...
Spoke too soon. Sketch appears to run fine with loop/noLoop controlling draw() action. But console outputs severe error and "check your code at runPause". Argh.
Can you post your whole code to reproduce your problem? One thing that comes to mind is calling noLoop(). I believe CP5 needs draw() to run to do its magic aka. to have the ability to interact with the user and to update variables and controller's member variables. I working example will help a lot here.
Kf
kfrajer: here's the code. Thanks for taking a look. It runs fine with toggling to pause and run draw().
Thanks again.
In my haste I forgot to deactivate code that relies on files not present above.
Please comment out the following lines: 64, and 71 through 77. The effect will still be demonstrated by the paused or running frame count. The console output - at least initial lines -- looks like this:
http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5toggle/ControlP5toggle.pde
Try:
boolean runPause=false; //GLOBAL scope
and
Kf
I added your suggested code changes and got the same error with the opening lines of the console error message shown above. After many lines of traceback, the console message ends with this:
"Heightfield_stripped" is the name of the edited sketch I sent above. This ending message suggests the code is responding to the toggle event, runPause(boolean theFlag), but sees a null pointer. Yet, except for the console error dump, the sketch runs as expected.
Furthermore, if I comment out the
runPause(boolean theFlag)
toggle event response, then the startup error does not occur. Great. However, theRunPauseToggle.setCaptionLabel()
command does not get executed so "RUNNING" persists. Also,frameCount
is continuously incremented in the background so when the toggle to resume occurs, the displayedframeCount
value jumps to the current value.We could just quit now on this problem. I didn't intend run/pause to be an important part of the user interface, I just started with it.
Thanks for your continued thoughts on this.
I get the same error if I keep your lines 80 to 87. The reason is that you have two functions that the controller can address. This is my code:
Regarding the counter jumping after it resumes, it is the way it suppose to work. The variable frameCount is an internal counter. If you want to have your own controlled counter, you can create one easily.
Kf
OK, I understand. I can live with a small side effect and will continue development. Thanks again.