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.