Object help new user

I’m a realtively new user. I’ve been watching Dan SHiffman videos and studying the examples given in the processing environment. Lately, I’ve been studying the example in the contributed libraries/controlP5/controllers/controlP5Button. In this example there is a function
<
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
n = 0;
}

The argument seems to be an Object(?). But I can not find it in the code. After nosing around a little it seems it is part of the controlP5 library and it is a Java Object. Is this correct? How can I better understand what the function shown above works? Thanks Mike
/>

please format code with </> button * homework policy * asking questions

please read the docu of controlP5

the function above is called automatically when a button is clicked for example and allows you to evaluate the button or whatever.

see https://github.com/sojamo/controlp5/blob/master/examples/controllers/ControlP5button/ControlP5button.pde

WHere do I find the document controlP5? This is exactly what I’m looking for. I would like to have the opportunity to read about things, rather than guess. Mike

I found a document on GitHub. Is this the document you are refering to? I intend to study this and hopefully it will help me out, thanks, Mike

I have to admit the documentation is not very good.

see http://www.sojamo.de/libraries/controlP5/#resources

There are also examples directly in the processing IDE:

  • Menu File | Examples | Contributed Libraries | ControlP5

Chrisir

Thanks for the reply. Holy Cow there is a large gap between the beginner YouTube videos and these examples. This is where I’m having trouble finding information regarding these items that are beyond the beginner stuff. I started to look over the cp5 radio button example. There is a lot of short cut items here that I can guess at, but what really has me stumped right now is the object method with two dot syntax.
for example;
<theEvent.getGroup().getValue()/>
I don’t want to ask questions for every item like this a comes up. I would like to see a good reference book with how this stuff works. Thanks Mike

Well I’m trying to understand how this code works, by guessing. Looking at the control P5 radiobutton example. It has some code;
< cp5 = new ControlP5(this);
r1 = cp5.addRadioButton(“radioButton”)
.setPosition(100,180)
.setSize(40,20)
.setColorForeground(color(120))
.setColorActive(color(255))
.setColorLabel(color(255))
.setItemsPerRow(5)
.setSpacingColumn(50)
.addItem(“50”,1)
.addItem(“100”,2)
.addItem(“150”,3)
.addItem(“200”,4)
.addItem(“250”,5)
;
/>
First what is “this” key word really do? Could I replace it with r1 in this simply example?
Then the rest seems to be a run on statement. There are no ; after each line and just one ; at the end. Is this some kind of short hand? How would you write it out in a long more visual descriptive way? I tried adding ;'s and cp5 prior to the dot’s and r1 = cp5 prior to the dot, but errors occur. Confused, Mike

here, the event is the radio button.
It consists of 5 items (the group).

so this: theEvent.getGroup() gives you the object group.

Then we get the value from the group (pressed item)

so this can be written in a row (theEvent.getGroup().getValue()), or you can tear it apart:

    println("\t "+theEvent.getValue());
    ControlGroup gr=theEvent.getGroup();   // step 1 
    myColorBackground = color(int(gr.getValue()*50), 0, 0);     // step 2

Yeah, did you check the JavaDoc?

http://www.sojamo.de/libraries/controlP5/reference/index.html

It’s a reference to your Sketch and hands a pointer to the Sketch. It’s a technical thing, dunno.

No.

Yes.

Yes.

all with the dot are referring to cp5.addRadioButton(“radioButton”)…

so a long form is to use r, the object we are referring to.


  // *********************************
  r = cp5.addRadioButton("radioButton");
  // *********************************

  r.setPosition(20, 160);
  r.setSize(40, 20);
  r.setColorForeground(color(120));
  r.setColorActive(color(255));
  r.setColorLabel(color(255));
  r.setItemsPerRow(5);
  r.setSpacingColumn(50);
  r.addItem("50", 1);
  r.addItem("100", 2);
  r.addItem("150", 3);
  r.addItem("200", 4);
  r.addItem("250", 5);

So when we init the radio button, we pass a lot of values / properties to it.

Chrisir

Thanks for the reply, I really appreciate your help. I’ve been reading about ‘this’. Apparently, it passes the current object, which I thought was r1 in the example, to the constructor of the class.Just to be clear, is the controlP5 the class and the .addRadioButton(), for example are functions within that class?
I tried the long notation and found that it still works. I think that I will use the long hand until I really understand what I’m doing.
The last question is in regard to the double dot stuff, for example,
<theEvent.getGroup().getValue()/>
Does this mean that within the function ‘theEvent’ there is another function ‘getGroup()’ and in that function another function getValue()?
Again I appreciate your help. Mike

  • A correction: theEvent isn’t a function but a function (aka method in Java) parameter.
  • A parameter is initialized by the argument passed to it when invoking its function.
  • That parameter theEvent is declared as datatype ControlEvent.
  • It means we can access any public member of that type using the operator . dot.
  • Inside that controlEvent() callback function we can see the method getGroup() is invoked over its parameter theEvent.
  • And after that another method named getName() is chain-invoked over the object returned by the method getGroup().
  • In order to know which datatype belongs the object returned by method getGroup() we need to read the docs about datatype ControlEvent though.

Thanks, I think I need some time to digest all this, but good stuff. Mike

1 Like