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

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.

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

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];
1 Like

1 Like

Thank you for the help ^^. It was useful