Get value from ScrollableList controlp5

Hi,
I’m trying to catch the value from a scrollable list created with controlp5.
This is an example I found online very similiar to what I have to do.

import controlP5.*;
import java.util.*;
 
ControlP5 cp5;
 
String selected = null;
 
void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
  cp5.addScrollableList("dropdown")
     .setPosition(100, 100)
     .setSize(200, 100)
     .setBarHeight(20)
     .setItemHeight(20)
     .addItems(l)
     ;
}
 
void draw() {
  background(120);
  if(selected != null) {
    text("You have selected: " + selected, 100, 300);
  }
}
 
//ControlP5 callback - method name must be the same as the string parameter of cp5.addScrollableList()
void dropdown(int index) {
  selected = cp5.get(ScrollableList.class, "dropdown").getItem(n).get("value");
}

When I type it in Processing it tells me “The variable n doesn’t exist”.
Has someone a clue on how can I do?

1 Like

In the dropdown method you are passing in (int index) and telling it to getItem(n). Try replacing n with index.

Hope this is clear.

2 Likes

Yes, it works, thank you!
I don’t know why I didn’t check it