# Making the variables into arrays, just to make the code more optimal

**URL:** <https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368>\
**Category:** Beginners\
**Created:** [December 18, 2020, 2:41pm UTC](https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368 "2020-12-18T14:41:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoWithTheFloe](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@GoWithTheFloe](https://discourse.processing.org/u/GoWithTheFloe)\
**Post date:** [December 18, 2020, 2:41pm UTC](https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368/1 "2020-12-18T14:41:14Z")

</div>

Hello,  
I am a beginner and I am trying to make my code more optimal and look more professional. I have some variables that are called the same but they all end with the numbers 0,1, 2 and so on. I ask this question while i am reducing the hardcode in the program, but i just want to get an example of how i can optimize these integers into an array.

The integers and booleans:

```
int xBubble0 = 330;
int xBubble1 = 330;
int xBubble2 = 330;
int xBubble3 = 330; 
int xBubble4 = 330;
int xBubble5 = 330;
int xBubble6 = 330; 

boolean condition1;
boolean condition2;
boolean condition3;
boolean condition4;

```

Then i use it to these text bubble images’ x positions. I have replaced them with ellipses instead if people wanna run the code, even though i haven’t posted setup and draw since it’s a massive code

```
void speaking0() {
ellipse(xBubble1, 20, 50);
ellipse(xBubble0, 20, 50);

condition1 = mouseX > xContinue0;
condition2 = mouseX < (xContinue0 + lContinue);
condition3 =(mouseY < yContinue + hContinue);
condition4 = (mouseY > yContinue);

if (condition1 && condition2 && condition3 && condition4) {
if (mousePressed) {
xBubble0 = 2000
}

```

I would also like to know how to do it for the voids as well, since i use void speaking0 and keep on using the same word with the number at the end changing, like i use void speaking1, void speaking 2…

Thank you, any help would be nice.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 18, 2020, 6:53pm UTC](https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368/2 "2020-12-18T18:53:41Z")

</div>

Sequences of values are called automatically in an array by their number.  
About storing functions in variables, that is not directly possible in Processing.

```auto
int[] my_integer_array;
boolean[] my_boolean_array;
int number_of_integers = 10;
int number_of_booleans = 10;

void setup() {
  my_integer_array = new int[number_of_integers];
  for (int i = 0; i < number_of_integers; i++) {
    my_integer_array[i] = 300;
  }
  my_boolean_array = new boolean[number_of_booleans];
  for (int i = 0; i < number_of_booleans; i++) {
    my_boolean_array[i] = true;
  }
  // Now you can call them by a number
  if (my_boolean_array[1] == true && my_boolean_array[4] == true) {
    int my_integer = my_integer_array[5];
    println(my_integer);
  }
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 18, 2020, 8:20pm UTC](https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368/3 "2020-12-18T20:20:13Z")

</div>

[Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays](http://Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays)

---

<div class="post-metadata">

**Author:** ![GoWithTheFloe](https://avatars.discourse-cdn.com/v4/letter/g/6de8d8/32.png) [@GoWithTheFloe](https://discourse.processing.org/u/GoWithTheFloe)\
**Post date:** [December 21, 2020, 2:33pm UTC](https://discourse.processing.org/t/making-the-variables-into-arrays-just-to-make-the-code-more-optimal/26368/4 "2020-12-21T14:33:54Z")

</div>

Thank you for the help ^^. It was useful
