# Get value from ScrollableList controlp5

**URL:** <https://discourse.processing.org/t/get-value-from-scrollablelist-controlp5/20752>\
**Category:** Libraries\
**Created:** [May 11, 2020, 4:40pm UTC](https://discourse.processing.org/t/get-value-from-scrollablelist-controlp5/20752 "2020-05-11T16:40:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matteocabe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matteocabe/32/493_2.png) [@matteocabe](https://discourse.processing.org/u/matteocabe)\
**Post date:** [May 11, 2020, 4:40pm UTC](https://discourse.processing.org/t/get-value-from-scrollablelist-controlp5/20752/1 "2020-05-11T16:40:54Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![tribblesontoast](https://avatars.discourse-cdn.com/v4/letter/t/e99b99/32.png) [@tribblesontoast](https://discourse.processing.org/u/tribblesontoast)\
**Post date:** [May 11, 2020, 10:20pm UTC](https://discourse.processing.org/t/get-value-from-scrollablelist-controlp5/20752/2 "2020-05-11T22:20:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![matteocabe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matteocabe/32/493_2.png) [@matteocabe](https://discourse.processing.org/u/matteocabe)\
**Post date:** [May 12, 2020, 7:33am UTC](https://discourse.processing.org/t/get-value-from-scrollablelist-controlp5/20752/3 "2020-05-12T07:33:29Z")

</div>

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