# Scrollable list to Bang

**URL:** <https://discourse.processing.org/t/scrollable-list-to-bang/857>\
**Category:** Coding Questions\
**Created:** [June 10, 2018, 10:42pm UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857 "2018-06-10T22:42:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GarethWilkins](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@GarethWilkins](https://discourse.processing.org/u/GarethWilkins)\
**Post date:** [June 10, 2018, 10:42pm UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857/1 "2018-06-10T22:42:06Z")

</div>

I have scrollable list and i want to use the picked items in these to feed into 4 bangs which will then play different sets of sounds. I am struggling working out how to get this info to the bangs. Any help will be greatly appreciated !

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 11, 2018, 1:35am UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857/2 "2018-06-11T01:35:02Z")

</div>

Please present a short code describing what you are doing and showing what parts you don’t understand. We are shooting in the dark here without this info.

Kf

---

<div class="post-metadata">

**Author:** ![GarethWilkins](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@GarethWilkins](https://discourse.processing.org/u/GarethWilkins)\
**Post date:** [June 11, 2018, 8:22am UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857/3 "2018-06-11T08:22:21Z")

</div>

```auto
import controlP5.*;
import java.util.*;
import processing.sound.*;

SoundFile file1;
SoundFile file2;

ControlP5 cp5;

void setup() {
  file1 = new SoundFile(this, "sound1.wav");
  file2 = new SoundFile(this,"sound2.wav");
  cp5 = new ControlP5(this);
  
  background(0); 
  size(1450,900);

List l = Arrays.asList("Option1","Option2");
  
  
  cp5.addScrollableList("list1")
  .setPosition(250,500)
  .setSize(100,40)
  .setBarHeight(20)
  .setItemHeight(20)
  .addItems(l)
  //.setType(ScrollableList.DROPDOWN)
  .setLabel("List 1 ");
  
   cp5.addBang("a_bang1")
     .setPosition(1100, 500)
     .setSize(40, 40)
     .setLabel("1") 
     ;
     cp5.addBang("a_bang2")
     .setPosition(1150, 500)
     .setSize(40,40)
     .setLabel("2")
     ;
}

void draw(){
}

void a_bang1(){
if ( // this is where I want to ask if the list1 has picked option 1){
file1.play();
}
else if ( // has option 2 been selected){
file2.play();
}
}

void a_bang2(){
if ( // this is where I want to ask if the list1has picked option 1){
file2.play();
}
else if ( // has option 2 been selected){
file1.play();
}
}

```

Does this make any sense to you. I also would like to see the labels on the bangs but they do not show. Any ideas?  
Thanks

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 12, 2018, 1:54am UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857/4 "2018-06-12T01:54:47Z")

</div>

Please make sure you format your code. You can edit your post, select your code and click on the `</>` button aka. the button to format your code.

I changed the name of your variable for a list as a single letter name “l” is not very descriptive. You should called it something meaningful, based on the functionality of this object in your program.

Have a look at this example. It is one way to do things and hopefully it will provide you some ideas that you can exploit yourself. The trick is to detect when the list was clicked. You will have a variable that stores the selection. Notice I init this variable to NO\_SELECTED in case the user runs the program and hits the bang button right way. Any other question or clarification, feel free to ask.

Kf

```java
import controlP5.*;
import java.util.*;
import processing.sound.*;

final int NO_SELECTED = -1;
SoundFile file1;
SoundFile file2;

ControlP5 cp5;
int listOneSelection;
List list;

void setup() {
  file1 = new SoundFile(this, "sound1.wav");
  file2 = new SoundFile(this, "sound2.wav");
  cp5 = new ControlP5(this);

  background(0);
  size(1450, 900);

  list = Arrays.asList("Option1", "Option2");
  listOneSelection=NO_SELECTED;

  cp5.addScrollableList("list1")
    .setPosition(250, 500)
    .setSize(100, 40)
    .setBarHeight(20)
    .setItemHeight(20)
    .addItems(list)
    //.setType(ScrollableList.DROPDOWN)
    .setLabel("List 1 ");

  cp5.addBang("a_bang1")
    .setPosition(1100, 500)
    .setSize(40, 40)
    .setLabel("1")
    ;
  cp5.addBang("a_bang2")
    .setPosition(1150, 500)
    .setSize(40, 40)
    .setLabel("2")
    ;
}

void draw() {
}

void list1(int n) {
  listOneSelection=n;
}

void a_bang1() {

  manageSoundSelection();

  //if (1==1) // this is where I want to ask if the list1 has picked option 1){
  // file1.play();
  //else if (1==1) // has option 2 been selected){
  // file2.play();
}

void a_bang2() {

  manageSoundSelection();

  //if (1==1) // this is where I want to ask if the list1has picked option 1){
  // file2.play();
  //else if (1==1) // has option 2 been selected){
  // file1.play();
}

void manageSoundSelection() {
  switch(listOneSelection) {
  case NO_SELECTED:
    println("Nothing to do. Please make sure you choose an item in list 1");
    break;
  case 0:
  case 1:
    println("You have selected item " + listOneSelection + " fro list1");
    break;
  default:
    break;
  }
}

```

---

<div class="post-metadata">

**Author:** ![GarethWilkins](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@GarethWilkins](https://discourse.processing.org/u/GarethWilkins)\
**Post date:** [June 12, 2018, 9:17am UTC](https://discourse.processing.org/t/scrollable-list-to-bang/857/5 "2018-06-12T09:17:19Z")

</div>

Thank You ⭐  
That has done the trick  
I can now see how it works
